Re: Accessing base method

From: Gavin K.

It’s not pretty, but:
[snip]

Though, of course, you can make it prettier by making it re-usable:

class Object
def supercall( method_name, *args )
self.class.superclass.instance_method( method_name ).bind( self
).call( *args )
end
end

class Parent
def knox
puts ‘parent’
end
end

class Child < Parent
def knox
puts ‘child’
end
def test
supercall( :knox )
end
end

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