From: David Chelimsky Date: 2006-07-13T12:08:42+09:00 Subject: Re: re-define class method On Jul 12, 2006, at 9:58 PM, David Chelimsky wrote: > I've got the following: > > module ClassMethods > def class_method > "Class method" > end > end > > class Thing > extend ClassMethods > end > > Thing.class_method > => "Class method" > > ... and I want to change the behaviour of that method at runtime. I > tried this: > > Thing.send(:define_method, :class_method, lambda{ "replaced" }) > > ... but I still get this: > > Thing.class_method > => "Class method" > > Am I close? What's the right way to do this? OK - I've discovered that I can do this: Thing.class.send(:define_method, :other_method, lambda{ "other" }) Thing.other_method => "other" and even redefine it: Thing.class.send(:define_method, :other_method, lambda{ "other redefined" }) Thing.other_method => "other redefined" but if I try this: Thing.class.send(:define_method, :class_method, lambda{ "replaced" }) Thing.class_method => "Class method" So it looks like I can replace class methods that I define at runtime, but not the ones that were defined at load-time. Is that correct? Am I missing a step? Thanks, David