hemant
12/6/2006 11:58:00 AM
On 12/6/06, Joerg Diekmann <joergd@pobox.com> wrote:
> Hi - not sure if this is possible - but it feels like it could be with
> some serious ruby-fu.
>
> I have the following:
>
> class A
> def method1
> method2
> end
>
> def method2
> return 100
> end
> end
>
> class B < A
> def method1
> super
> end
>
> def method2
> return 200
> end
> end
>
>
> This is what happens:
>
> b.method1 # 200
>
> But, what I want is:
>
> b.method1 # 100
>
>
> Is this possible at all?
>
> Thanks
> Joerg
Indeed but sometime back, we had similar discussion here and someone
(David I guess) proposed:
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
--
There was only one Road; that it was like a great river: its springs
were at every doorstep, and every path was its tributary.