On Thu, 2004-09-30 at 22:20, Andrew Johnson wrote:
> ## Or, add dynamic call_up to the Object class:
> class Object
>   def supercede(meth)
>     self.class.superclass.instance_method(meth).bind(self).call
>   end
>   alias :call_up :supercede
> end
> 
> a.h                                                  #=> 'bar'
> a.supercede(:h)                                      #=> 'foo'
> a.call_up(:h)                                        #=> 'foo'
> __END__

supercede is nice. To build on that:

[...]
class Object
  def supercede(meth, n = 1)
    klass = (1..n).inject(self.class) do |klass,|
      klass.__send__ :superclass
    end
    klass.instance_method(meth).bind(self).call
  end
end

a.h                                                  #=> 'bar'
a.supercede(:h)                                      #=> 'foo'
a.supercede(:h, 2)                                   #=> 'foobar'

-- 
_="puts'_='+_.inspect+';'+_";puts'_='+_.inspect+';'+_