George
11/12/2007 7:34:00 AM
On Nov 12, 2007 4:53 PM, Thilina Buddhika <thilinamb@gmail.com> wrote:
>
> but i want to get only the methods defined by my self. Is there any way
> to solve this ?
This gives the same result as the others, but avoids hardcoding method names:
$ cat toplevel_methods.rb
TOPLEVEL_METHODS = []
def Object.method_added(name)
TOPLEVEL_METHODS << name if private_method_defined?(name)
end
def toplevel
end
class Object
def not_toplevel
end
private
def fake_toplevel
end
end
p TOPLEVEL_METHODS
$ ruby toplevel_methods.rb
[:toplevel, :fake_toplevel]