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