# Reflecting on methods

**URL:** <https://www.ruby-forum.com/t/reflecting-on-methods/107431>\
**Category:** Ruby\
**Created:** [June 21, 2007, 7:11pm UTC](https://www.ruby-forum.com/t/reflecting-on-methods/107431 "2007-06-21T19:11:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 21, 2007, 7:11pm UTC](https://www.ruby-forum.com/t/reflecting-on-methods/107431/1 "2007-06-21T19:11:13Z")

</div>

Hi guys !

I’m a little bit confused about the right way to get the methods of a  
class/module.

For this class

class Test  
public  
def Test.pub\_class\_meth; end

protected  
def Test.prot\_class\_meth; end

private  
def Test.priv\_class\_meth; end

public  
def pub\_meth; end

protected  
def prot\_meth; end

private  
def priv\_meth; end  
end

arr = []  
Object.methods.each {|m| arr \<\< m if m =~ /methods/}  
arr.each {|m| puts m + " = [" + (Test.send(m) -  
Object.send(m)).join(", ") + “]”}

I get the following result:

methods = [priv\_class\_meth, pub\_class\_meth, prot\_class\_meth]  
private\_instance\_methods = [priv\_meth]  
singleton\_methods = [priv\_class\_meth, prot\_class\_meth, pub\_class\_meth]  
instance\_methods = [pub\_meth, prot\_meth]  
protected\_methods = []  
private\_methods = []  
public\_instance\_methods = [pub\_meth]  
protected\_instance\_methods = [prot\_meth]  
public\_methods = [priv\_class\_meth, pub\_class\_meth, prot\_class\_meth]

Question: Why is “prot\_meth” not listed in protected\_methods ? And  
“priv\_meth” in private\_methods ?  
In general: Which of these \*\_methods gives which result ?

Thanks in advance

Dominik

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 22, 2007, 1:01am UTC](https://www.ruby-forum.com/t/reflecting-on-methods/107431/2 "2007-06-22T01:01:01Z")

</div>

> Question: Why is “prot\_meth” not listed in protected\_methods ? And “priv\_meth” in private\_methods ?  
> In general: Which of these \*\_methods gives which result ?

You are calling .protected\_methods and .private\_methods on the Test  
class object, not a Test instance object.

This code:  
%w(protected\_methods private\_methods).each {|m| puts m + " = [" +  
(Test.new.send(m) - Object.new.send(m)).join(’,’) + “]” }  
gives:  
protected\_methods = [prot\_meth]  
private\_methods = [priv\_meth]

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [June 22, 2007, 3:24am UTC](https://www.ruby-forum.com/t/reflecting-on-methods/107431/3 "2007-06-22T03:24:14Z")

</div>

Yeah, that’s it !!!  
Guess I was blind…

Thanks a lot !

Dominik

2007/6/22, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
