Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- irb(main):001:0> class Foo; def method1; puts 1; end; end
- => nil
- irb(main):002:0> foo = Foo.new
- => #<Foo:0xb79fa724>
- irb(main):003:0> def foo.method2; puts 2; end
- => nil
- irb(main):004:0> foo.method1
- 1
- => nil
- irb(main):005:0> foo.method2
- 2
- => nil
- irb(main):006:0> other_foo = Foo.new
- => #<Foo:0xb79f0ef4>
- irb(main):007:0> other_foo.method1
- 1
- => nil
- irb(main):008:0> other_foo.method2
- NoMethodError: undefined method `method2' for #<Foo:0xb79f0ef4>
- from (irb):8
- irb(main):009:0> Foo.method_defined? :method1
- => true
- irb(main):010:0> Foo.method_defined? :method2
- => false
- irb(main):012:0> singleton_class = ( class << foo; self; end )
- => #<Class:#<Foo:0xb79fa724>>
- irb(main):013:0> singleton_class.method_defined? :method1
- => true
- irb(main):014:0> singleton_class.method_defined? :method2
- => true
- irb(main):015:0> other_singleton_class = ( class << other_foo; self; end )
- => #<Class:#<Foo:0xb79f0ef4>>
- irb(main):016:0> other_singleton_class.method_defined? :method1
- => true
- irb(main):017:0> other_singleton_class.method_defined? :method2
- => false
- irb(main):018:0> class << foo; def method3; puts 3; end; end
- => nil
- irb(main):019:0> foo.method3
- 3
- => nil
- irb(main):022:0> Foo.method_defined? :method3
- => false
Add Comment
Please, Sign In to add comment