Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get class methods?

Tags:

ruby

Ruby Module has a method instance_methods that can return a list of methods of that class. But how to retrieve class methods list of a class?

like image 500
TieDad Avatar asked Nov 28 '13 10:11

TieDad


2 Answers

You can pass the false parameter to Object#methods.

class Foo
  def self.bar
  end
end

Foo.methods(false) #=> [:bar]
like image 158
user2422869 Avatar answered Sep 27 '22 21:09

user2422869


Go to rails console with the command:

rails c

type:

 Class.methods 

and you will get them all in a list.

If you want to get a specific class' method, then type:

Class_name.methods
like image 31
Francisca Vargas Avatar answered Sep 27 '22 21:09

Francisca Vargas