From: Brian Adkins Date: 2007-12-18T23:05:01+09:00 Subject: Re: Difference between alias and alias_method On Dec 17, 12:42 pm, Chan Sammy wrote: > In the example below, I really can't sort out why using alias_method > will work, while using alias won't. Could someone shred me some light > on this? Thanks. I believe it's a scoping issue. Move the alias statement so that it's within the module_eval block as below: > class T > def initialize() > puts "T's initialize" > end > def self.redefine > self.module_eval do > alias old_initialize initialize > define_method :initialize do > old_initialize(1) > end > end > end > end > > class S < T > def initialize(int) > puts "S's initialize:#{int}" > end > redefine() > end > S.new > > ========================== > Using alias: > in `old_initialize': wrong number of arguments (1 for 0) (ArgumentError) > (T's initialize was called) > > Using alias_method: > S's initialize:1 > (S's initialize was called, as expected)