Skip to content

Instantly share code, notes, and snippets.

@rkh
Created May 6, 2013 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkh/5525960 to your computer and use it in GitHub Desktop.
Save rkh/5525960 to your computer and use it in GitHub Desktop.
irb(main):004:0> ObjectSpace.each_object.all? {|o| o.methods.all? {|m| o.method(m).owner.instance_methods.include?(m) }}
=> true
irb(main):005:0> RUBY_VERSION
=> "2.0.0"
@rentalcustard
Copy link

Yes, but:

2.0.0p0 :004 > self.method(:using).owner.instance_methods.include?(:using)
 => false

@rkh
Copy link
Author

rkh commented May 6, 2013

oh, so, it's the magic main object

@rentalcustard
Copy link

That's part of the story...

2.0.0p0 :005 > ObjectSpace.each_object.include?(self) 
=> true 
2.0.0p0 :006 > self 
=> main
2.0.0p0 :010 > self.methods.include?(:using)
 => false
2.0.0p0 :016 > self.method(:using).owner == self.singleton_class
 => true
2.0.0p0 :019 > self.singleton_class.instance_methods.include?(:using)
 => false
2.0.0p0 :020 > self.singleton_class.methods.include?(:using)
 => false

@rkh
Copy link
Author

rkh commented May 6, 2013

irb(main):015:0> private_methods.include? :using
=> true
irb(main):016:0> singleton_class.private_instance_methods.include? :using
=> true

@rentalcustard
Copy link

You found it! You are a true Ruby Hero.

@rkh
Copy link
Author

rkh commented May 6, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment