Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If I define a method in Ruby, does it belong to any class?

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?

like image 532
Andrei Avatar asked Dec 06 '22 02:12

Andrei


1 Answers

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

like image 59
sepp2k Avatar answered Dec 11 '22 10:12

sepp2k