Miguel Salas
Miguel Salas

Reputation: 701

How to list instance methods of an object class without listing the methods of the superclasses

The method methods returns a list of all methods of a class, for example if I call 'miguel'.methods, I will get a list of all the methods in the class String.

I would like to list the methods of a class, excluding the methods of its superclasses. For example, a list of instance methods that are defined on String, including modules included into String.

I also would like to know how to list instance methods that are exclusively defined on the object class without listing instance methods included in modules included by the class.

Upvotes: 0

Views: 141

Answers (1)

Ashik Salman
Ashik Salman

Reputation: 1879

Try this:

class.instance_methods(false)

Here for string as example:

'miguel'.class.instance_methods(false)

Upvotes: 1

Related Questions