Created
September 6, 2012 03:19
-
-
Save alindeman/3650631 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Foo | |
| def hello | |
| :regular_instance_method | |
| end | |
| end | |
| def singleton_class_for(obj) | |
| class << obj; self; end | |
| end | |
| # public_instance_methods(false) is supposed to give a list of methods defined | |
| # on the Class or Module, *not including ancestors* | |
| # I expect these values: | |
| # On 1.9.2, 1.9.3: [:hello] | |
| # On 1.8.7: ["hello"] | |
| p Foo.public_instance_methods(false) | |
| # On 1.9.2, 1.9.3: [] | |
| # On 1.8.7: ["hello"] <-- WHY? I DID NOT EXPECT THIS | |
| p singleton_class_for(Foo.new).public_instance_methods(false) |
Author
@myronmarston, good point, but it's possible in my use case that it'll be defined in both places. I want to know definitively if it's defined on the singleton class, regardless of whether it's on any superclass.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you use this?
That returns
[]on both 1.8.7 and 1.9.