Aliasing and Inheritance

Hi,

apparently aliased methods are not inherited. Why is that so?

irb(main):001:0> class A
irb(main):002:1> def a; puts “A”; end
irb(main):003:1> alias :b :a
irb(main):004:1> end
nil
irb(main):005:0>
irb(main):006:0* class B
irb(main):007:1> def a; puts “B”; end
irb(main):008:1> end
nil
irb(main):009:0>
irb(main):010:0* A.new.a
A
nil
irb(main):011:0> A.new.b
A
nil
irb(main):012:0> B.new.a
B
nil
irb(main):013:0> B.new.b
NoMethodError: undefined method `b’ for #<B:0x2a525d0>
from (irb):13
irb(main):014:0>

Regards

robert

class B < A
is what you need :slight_smile:

Regards,

Brian.

···

On Thu, Jul 31, 2003 at 04:17:21PM +0900, Robert Klemme wrote:

apparently aliased methods are not inherited. Why is that so?

irb(main):001:0> class A
irb(main):002:1> def a; puts “A”; end
irb(main):003:1> alias :b :a
irb(main):004:1> end
nil
irb(main):005:0>
irb(main):006:0* class B
irb(main):007:1> def a; puts “B”; end
irb(main):008:1> end

“Brian Candler” B.Candler@pobox.com schrieb im Newsbeitrag
news:20030731072955.GB94634@uk.tiscali.com

···

On Thu, Jul 31, 2003 at 04:17:21PM +0900, Robert Klemme wrote:

apparently aliased methods are not inherited. Why is that so?

irb(main):001:0> class A
irb(main):002:1> def a; puts “A”; end
irb(main):003:1> alias :b :a
irb(main):004:1> end
nil
irb(main):005:0>
irb(main):006:0* class B
irb(main):007:1> def a; puts “B”; end
irb(main):008:1> end

class B < A
is what you need :slight_smile:

Ouch!

Must’ve been still sleeping…

/me goes into a corner and sobs silently

robert