So Close Yet So Far
class Module
private
def override_method( name, &body )
begin
supr = instance_method( name )
rescue NameError
supr = lambda {}
end
define_method( name ) { |*args|
body.call( supr.bind(self), *args )
}
end
end
class Bar
def bar
p self
p 1
end
end
class Foo < Bar
override_method( :bar ) { |supr|
supr.call
p self
p 2
}
override_method( :bar ) { |supr|
supr.call
p self
p 3
}
end
Foo.new.bar
Now if I could just figure out how to re-jigger self when calling the block passed to override_method, as define_method obviously does…