Hello --


On Thu, 1 Nov 2001, Paul Brannan wrote:

> On Thu, 1 Nov 2001, ts wrote:
>
> > >>>>> "P" == Paul Brannan <pbrannan / atdesk.com> 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 #<Object:0x40180b14>
        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