Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > getting method names for a Class

Reply
Thread Tools

getting method names for a Class

 
 
Mark Volkmann
Guest
Posts: n/a
 
      02-10-2006
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 J=
ava.
To get the names of public *class* methods in the class Foo, use
Foo.methods(false).

Foo.methods(false) =3D=3D 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.

--
R. Mark Volkmann
Partner, Object Computing, Inc.


 
Reply With Quote
 
 
 
 
David Vallner
Guest
Posts: n/a
 
      02-10-2006
D=C5=88a Piatok 10 Febru=C3=A1r 2006 16:46 Mark Volkmann nap=C3=ADsal:
> 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) =3D=3D 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.
>
> --
> R. Mark Volkmann
> Partner, Object Computing, Inc.


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

David Vallner


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting test method names when getting output Hunt Jon Ruby 2 12-18-2008 03:00 PM
why a class can't access protected method from another class in thesame package,the method is interited from the ohtner class from differntpackage? junzhang1983@gmail.com Java 3 01-28-2008 02:09 AM
Getting method name from within the class method Mitko Haralanov Python 17 10-20-2006 02:11 AM
Re: fetching method names from a class,and the parameter list from a method John Lenton Python 0 01-11-2005 05:12 AM
member function names identical to class names Ares Lagae C++ 8 09-24-2004 11:23 AM



Advertisments