never_had_a_name
never_had_a_name

Reputation: 93216

List methods only in a module?

I wonder how one can list all methods in a module, but not including inherited methods.

eg.

module Software
  def exit
    puts "exited"
  end
end

puts Software.methods

Will list not only exit, but all inherited methods.

Is is possible to just list exit?

Thanks

Upvotes: 37

Views: 19866

Answers (2)

sepp2k
sepp2k

Reputation: 370172

Actually Software.methods will not list exit. Software.instance_methods will list exit as well as any inherited methods (which in this case is nothing because modules don't inherit any methods unless you include another module). Software.instance_methods(false) will only list methods defined in Software.

Upvotes: 57

Beanish
Beanish

Reputation: 1662

Software.public_instance_methods

seems to work for your example.

Upvotes: 36

Related Questions