views:

76

answers:

4

I have feeling, that if one defines a method

def test
  puts 'Hi'
end

then there is a class to which this method belongs to (i.e. Unknown#test). So one probably has a possibility to list all methods defined "outside" of other classes. Or there is another way to do such listing?

+5  A: 

If you define a method outside of any class, it will become a private method of the Object class.

sepp2k
+4  A: 

A top-level method is a private method of Object. Check out this question.

Mk12
Thanks for the link!
Andrey
+3  A: 

In future, to find what object a method belongs to, do this:

method(:test).owner

Output, for your example is Object

banister
+1  A: 

And you can then list all the methods of Object with

Object.send(:methods)

or

Object.send(:private_methods)
Cedric H.