On Wed, Oct 19, 2011 at 3:16 PM, salamond <jarodzz / gmail.com> wrote:

> My problem is this:
> When I overwrite a method in sub class, is there a way I can keep the
> original class calling its own method?

There is a way (line 15) but it's horrible:

irb(main):001:0> class Base
irb(main):002:1> def a;"base";end
irb(main):003:1> def b;a;end
irb(main):004:1> end
=> nil
irb(main):005:0> class Derived < Base
irb(main):006:1> def a;"derived";end
irb(main):007:1> end
=> nil
irb(main):008:0> Base.new.a
=> "base"
irb(main):009:0> Derived.new.a
=> "derived"
irb(main):010:0> class Base
irb(main):011:1> end
=> nil
irb(main):012:0> Derived.new.b
=> "derived"
irb(main):013:0> Base.new.b
=> "base"
irb(main):014:0> class Base
irb(main):015:1> def b;Base.instance_method(:a).bind(self).call;end
irb(main):016:1> end
=> nil
irb(main):017:0> Base.new.b
=> "base"
irb(main):018:0> Derived.new.b
=> "base"

In short: you don't want to do this.  Rather lay out your methods in a
way that it's not necessary.  Btw, it's similar in other languages.

Kind regards

robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/