From: Tim Pease Date: 2007-01-13T04:51:02+09:00 Subject: Re: Rake, Hoe, Meta-Programming, and Warnings (oh my!) On 1/12/07, James Edward Gray II wrote: > On Jan 12, 2007, at 11:24 AM, Tim Pease wrote: > > > The warnings are coming from some meta-programming code that is > > redefining instance methods on the fly based on user input. So maybe a > > better question would be, is there a way to redefine methods without > > causing Ruby to spew out a warning each time the method is redefined. > > Sure. Watch: > > #!/usr/bin/env ruby -w > > class Test > def override > "original" > end > end > > Test.new.override # => "original" > > class Test > def override # !> method redefined; discarding old override > "warning" > end > end > > Test.new.override # => "warning" > > class Test > undef :override > def override > "no warning" > end > end > > Test.new.override # => "no warning" > > class Test > alias_method :old_override, :override > def override > "alias avoids warning too" > end > end > > Test.new.override # => "alias avoids warning too" > > __END__ > > Hope that helps. > Hey James! That did the trick. I could have sworn that I tried undef before, but in my current sleep deprived state I'm not too sure about it. Hmmm ... I most likely did try undef, but it chucked an exception at me when I tried to undef a non-existent method. Now using undef along with method_defined? All is well :) Blessings, TwP