Class Methods

Here’s some simple code:

def ClassA
def my_method

end
end

def ClassB < ClassA
def my_new_method

end
end


What is the best way to get a list of instance methods for ClassB, but
that
does not contain the parent class’s methods?

ClassB.instance_methods is returning all of them. I just want to see
‘my_new_method’.

Any ideas?

Michael G. wrote:

What is the best way to get a list of instance methods for ClassB, but
that
does not contain the parent class’s methods?

ClassB.instance_methods is returning all of them. I just want to see
‘my_new_method’.

ClassB.instance_methods - ClassB.superclass.instance_methods

“M” == Michael G. [email protected] writes:

M> ClassB.instance_methods is returning all of them. I just want to see
M> ‘my_new_method’.

ClassB.instance_methods(false)

Guy Decoux

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs