user2012677
user2012677

Reputation: 5735

Method to find just my custom methods I wrote, not any inherited methods (Ruby)

class Foo

   def initialize()
   end

   def cow
   end

   def dog
   end

   def any_other
   end
end

What method can I use to find just my custom defined methods, cow, dog, and any_other, and not any of the base methods?

Foo.custom_methods
>>
:cow
:dog
:any_other

Upvotes: 2

Views: 79

Answers (1)

max pleaner
max pleaner

Reputation: 26758

You can use Foo.instance_methods(false) to get the instance methods, and Foo.methods(false) to get the class methods.

The false argument is saying dont show inherited methods.

Upvotes: 4

Related Questions