Skip to content

Instantly share code, notes, and snippets.

@alindeman
Created September 6, 2012 03:19
Show Gist options
  • Select an option

  • Save alindeman/3650631 to your computer and use it in GitHub Desktop.

Select an option

Save alindeman/3650631 to your computer and use it in GitHub Desktop.
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)
@myronmarston
Copy link

Can you use this?

(singleton_class_for(Foo.new).public_instance_methods(false) - Foo.public_instance_methods(false))

That returns [] on both 1.8.7 and 1.9.

@alindeman
Copy link
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