Forum: Ruby getting method names for a Class

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
52a177e9dbd3e614825aabc4e45f8cd6?d=identicon&s=25 Mark Volkmann (Guest)
on 2006-02-10 16:46
(Received via mailing list)
There are so many methods in Object and Module that return arrays of
method names that it can be a bit confusing. Here's a summary of my
current understanding. Is any of this wrong?

"instance_methods" is a method from Module.
Pass it true to include inherited methods (the default) and false to
exclude them.
To get the names of public *instance* methods in the class Foo, use
Foo.instance_methods.

"methods" is a method from Object.
Pass it true to get instance methods (the default) and false to get
singleton methods.
A singleton method on a Ruby Class is essentially like a static method
in Java.
To get the names of public *class* methods in the class Foo, use
Foo.methods(false).

Foo.methods(false) == Foo.singleton_methods(false)

Why doesn't Foo.methods(true)  return the same thing as
Foo.instance_methods(true)?

I can see using a boolean parameter to tell whether you want inherited
methods to be included (as in the instance_methods method). However,
using a boolean parameter to tell whether you want instance or
singleton methods (as in the method "methods") seems bad. Maybe that
should be deprecated in favor of instance_methods and
singleton_methods.
430ea1cba106cc65b7687d66e9df4f06?d=identicon&s=25 David Vallner (Guest)
on 2006-02-10 19:24
(Received via mailing list)
DÅ?a Piatok 10 Február 2006 16:46 Mark Volkmann napísal:
> "methods" is a method from Object.
>
> I can see using a boolean parameter to tell whether you want inherited
> methods to be included (as in the instance_methods method). However,
> using a boolean parameter to tell whether you want instance or
> singleton methods (as in the method "methods") seems bad. Maybe that
> should be deprecated in favor of instance_methods and
> singleton_methods.
>
> --
> R. Mark Volkmann
> Partner, Object Computing, Inc.

Because #instance_methods shows methods an instance of Foo will have,
and
#methods and #singleton_methods show you methods of the class object
Foo?
Just a guess there.

David Vallner
This topic is locked and can not be replied to.