# Getting method names for a Class

**URL:** <https://www.ruby-forum.com/t/getting-method-names-for-a-class/65428>\
**Category:** Ruby\
**Created:** [February 10, 2006, 4:46pm UTC](https://www.ruby-forum.com/t/getting-method-names-for-a-class/65428 "2006-02-10T16:46:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![markcasio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9bcb4/32.png) [@markcasio](https://www.ruby-forum.com/u/markcasio)\
**Post date:** [February 10, 2006, 4:46pm UTC](https://www.ruby-forum.com/t/getting-method-names-for-a-class/65428/1 "2006-02-10T16:46:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![markcasio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9bcb4/32.png) [@markcasio](https://www.ruby-forum.com/u/markcasio)\
**Post date:** [February 10, 2006, 7:24pm UTC](https://www.ruby-forum.com/t/getting-method-names-for-a-class/65428/2 "2006-02-10T19:24:34Z")

</div>

DÅ?a Piatok 10 FebruÃ¡r 2006 16:46 Mark V. 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 V.  
> 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 V.
