From: Ryan Leavengood Date: 2005-06-27T05:31:25+09:00 Subject: Re: Defining a method vs aliasing it David A. Black wrote: > > I believe it's the other way around: aliasing a method name just adds > another name for the same method. If you then redefine the original > method, the two names then point to different methods: > > class C > def x; end > alias :y :x # y and x are the same method > def x; "new method"; end # they are not the same > end > > At least that's always been my understanding of it. I thought you were correct, and irb agrees: irb(main):001:0> class C 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> c = C.new => # irb(main):006:0> c.a a => nil irb(main):007:0> c.b a => nil irb(main):008:0> ma = c.method(:a) => # irb(main):009:0> mb = c.method(:b) => # irb(main):010:0> ma.call a => nil irb(main):011:0> mb.call a => nil irb(main):012:0> ma == mb => true irb(main):013:0> ms = c.method(:to_s) => # irb(main):014:0> ms.call => "#" irb(main):015:0> ms == ma => false irb(main):016:0> class C irb(main):017:1> def b;puts 'b';end irb(main):018:1> end => nil irb(main):019:0> c.b b => nil irb(main):020:0> ma == mb => true irb(main):021:0> mb = c.method(:b) => # irb(main):022:0> ma == mb => false Ryan