From: Lyle Johnson Date: 2002-09-29T05:29:09+09:00 Subject: alias versus method_missing All, Before I make this harder than it is, I wanted to double-check. Let's say I have a base class: class Base def foo puts "inside Base#foo" end end and another class derived from Base: class Derived < Base def foo puts "inside Derived#foo" end end Now suppose I'd like to set up "bar" as an alias for "foo", such that if I invoke "bar" on a Base instance (or an instance of any of Bar's subclasses) that it will turn around and call "foo" for that instance instead, i.e. b = Base.new d = Derived.new b.bar -> prints "inside Base#foo" d.bar -> prints "inside Derived#foo" I'm finding that if I simply add an alias in the base class: class Base alias bar foo end that doesn't cut it; "bar" always invokes Base#foo. And I guess I understand why. But I was trying to figure out if there's an alternative that gets me what I really wanted (sort-of a "virtual alias"). I think I can make it work using method_missing instead of alias, e.g. class Base def method_missing(mid, *args) case mid when :bar foo(*args) else super # hand off to Base's base class... end end end but this is obviously a lot more verbose (especially since I'll ultimately have lots of aliases, in lots of classes). Is there some more compact approach that I'm forgetting about? Thanks in advance, Lyle