From: David Alan Black Date: 2001-11-01T02:45:07+09:00 Subject: [ruby-talk:23995] Re: Strangeness with undefining methods Hello -- On Thu, 1 Nov 2001, Paul Brannan wrote: > On Thu, 1 Nov 2001, ts wrote: > > > >>>>> "P" == Paul Brannan writes: > > > > P> If 'foo' is already removed, then why do I get the "discarding old foo" > > P> message? > > > > foo is not removed just undef, try > > > > class Object; remove_method :foo; end > > Ahh, that makes sense, thanks. > > In what real world situation might I use undef instead of remove_method? > And when I undef a method, where does the method go, since I can't call > it? (I've noticed that I can still call remove_method after an undef). I use undef instead of remove_method in Ruby Behaviors, to get rid of aliases. (At least in the current implementation :-) The method hangs around, and you can still get at it with any aliases that might exist: irb(main):001:0> def thing; puts "hi"; end nil irb(main):002:0> alias :other :thing nil irb(main):003:0> undef thing nil irb(main):004:0> thing NameError: undefined local variable or method `thing' for # from (irb):4 irb(main):005:0> other hi David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav