Re: Accessing base method

From: Soso S.

I’m new to ruby, being trying to access base class method but with no
luck until now. Here’s a snippet to get an idea:

It’s not pretty, but:

class Parent
def knox
puts ‘parent’
end
end

class Child < Parent
def knox
puts ‘child’
end
def test
self.class.superclass.instance_method( :knox ).bind( self ).call
end
end

Child.new.test
#=> ‘parent’

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