Undef_method cutting off subclass's method lookup?

class Numeric
    def succ
      self + 1
    end
  end

  class Integer
    undef_method( :succ )
  end

  2.class #=> Fixnum
  2.succ
  NoMethodError: undefined method `succ' for 1:Fixnum
          from (irb):10

Shouldn't it be able to find #succ in the ancestor?

T.

Hi --

···

On Mon, 1 Nov 2004, trans. (T. Onoma) wrote:

  class Numeric
    def succ
      self + 1
    end
  end

  class Integer
    undef_method( :succ )
  end

  2.class #=> Fixnum
  2.succ
  NoMethodError: undefined method `succ' for 1:Fixnum
          from (irb):10

Shouldn't it be able to find #succ in the ancestor?

From 'ri undef_method':

----------------------------------------------------
Module#undef_method
     undef_method(symbol) => self
------------------------------------------------------------------------
     Prevents the current class from responding to calls to the named
     method. Contrast this with +remove_method+, which deletes the
     method from the particular class; Ruby will still search
     superclasses and mixed-in modules for a possible receiver.

David

--
David A. Black
dblack@wobblini.net

Sigh. So I should use #remove_method then. Okay. That's bit me again. Yes, I
know this. But I use it rarely, and when I do I keep getting confused about
which is which. The above is terribly written. The statement after the
semicolon doesn't have a clear reference. Is the semicolon supposed to clue
me in? That's weak, and one wonders which of the two will "still search".
Moreover, it says _current class_, not _current class and all subclasses
thereof_, so that seems misleading too.

Anyway, thanks David!
T.

···

On Sunday 31 October 2004 03:02 pm, David A. Black wrote:

Hi --

On Mon, 1 Nov 2004, trans. (T. Onoma) wrote:
> class Numeric
> def succ
> self + 1
> end
> end
>
> class Integer
> undef_method( :succ )
> end
>
> 2.class #=> Fixnum
> 2.succ
> NoMethodError: undefined method `succ' for 1:Fixnum
> from (irb):10
>
>
> Shouldn't it be able to find #succ in the ancestor?

From 'ri undef_method':

----------------------------------------------------
Module#undef_method
     undef_method(symbol) => self
------------------------------------------------------------------------
     Prevents the current class from responding to calls to the named
     method. Contrast this with +remove_method+, which deletes the
     method from the particular class; Ruby will still search
     superclasses and mixed-in modules for a possible receiver.