0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ファイルで定義したメソッドの一覧を取得する

Last updated at Posted at 2020-11-18

Railsのモデルなど、各ファイルのメソッドの調査をirbで行いたかったので、以下のようなスクリプトを作成した。

methods = []
File.foreach("foo.rb") { |line|
  methods << line.chomp.gsub(/^\s*def\s/, '').gsub(/\(.+\)/, '') if /^\s*def\s/ =~ line
}

趣旨からは外れるがアプリの挙動をコンソールで確認できるのであれば、クラスメソッドとインスタンスメソッドを分けるのは以下でできる。

instance_methods = Foo.instance_methods(false)
private_instance_methods = Foo.private_instance_methods(false)
class_methods = Foo.methods(false)
private_class_methods = Foo.private_methods(false)
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?