From: Robert Dober Date: 2007-07-23T02:47:51+09:00 Subject: Re: How do you "undef_method" for a class method? On 7/22/07, Chris Thiel wrote: > Well, not sure if there's a more elegant approach to this (and there > probably is) but one way to do it would be to open up the class itself and > redfine the method to do nothing or raise an exception. I'm curious to see > if there *is* another way to do this, though. Let me plead you not to top post first ;) and then give you the answer > > Chris > > > On 7/22/07, Dean Wampler wrote: > > > > Module#undef_method and Module#remove_method work fine for instance > > methods, > > but if you specify a class method, your get an error that it doesn't > > exist. > > (I'm using ruby 1.8.6.) > > > > Is there a way to do this? TIA. > > > > Dean > > > > -- > > Dean Wampler > > http://www.objectmentor.com > > http://www.aspectprogramming.com > > http://www.contract4j.org > > > 505/5 > cat remove_method.rb && ruby remove_method.rb class A def A.hi "hello" end end p A.hi class << A remove_method :hi end p A.hi "hello" remove_method.rb:11: undefined method `hi' for A:Class (NoMethodError) robert@PC:~/log/ruby/ML 19:46:46 If memory serves you should not use undefine_method as it leaks. HTH Robert -- We're on a mission from God. ~ Elwood,