Skip to content

Instantly share code, notes, and snippets.

@mizoR
Created September 26, 2012 02:54
Show Gist options
  • Save mizoR/3785734 to your computer and use it in GitHub Desktop.
Save mizoR/3785734 to your computer and use it in GitHub Desktop.
インスタンスメソッドの中で、メソッド定義を書いたときの挙動
➜ ~ irb
irb(main):001:0> class MyClass
irb(main):002:1> def one
irb(main):003:2> def two
irb(main):004:3> 'hello'
irb(main):005:3> end
irb(main):006:2> end
irb(main):007:1> end
=> nil
irb(main):008:0> MyClass.instance_methods(false).grep /one/
=> [:one]
irb(main):009:0> MyClass.instance_methods(false).grep /two/
=> []
irb(main):010:0> MyClass.new.one
=> nil
irb(main):011:0> MyClass.instance_methods(false).grep /two/
=> [:two]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment