Object#undef_method?

Folks,

You can remove a method from a class or module using Module#remove_method
and Module#undef_method. What if the method you are trying to get rid of
is a _singleton_ method?

For instance,

  module X
    def X.foo() 4 end
  end

  X.foo # -> 4

  # Some code goes here.

  X.foo # -> NameError: undefined method `foo' for X:module [1]

Please write the code in the placeholder.

[1] Or 'NoMethodError'; I can't tell which is which.

A related question. I want to remove a method and redefine it. Why not
just overwrite it? Because that raises a warning. I don't want to run
the code without warnings, and I don't want to have to fiddle with the
warning level at runtime. Any comments appreciated.

Cheers,
Gavin

Hi,

At Tue, 31 Aug 2004 15:20:04 +0900,
Gavin Sinclair wrote in [ruby-talk:111071]:

  module X
    def X.foo() 4 end
  end

  X.foo # -> 4

    class << X
      remove_method(:foo)
    end

···

  X.foo # -> NameError: undefined method `foo' for X:module [1]

--
Nobu Nakada

You can remove a method from a class or module using Module#remove_method
and Module#undef_method. What if the method you are trying to get rid of
is a _singleton_ method?

For instance,

  module X
    def X.foo() 4 end
  end

  X.foo # -> 4

  # Some code goes here.

class << X; undef_method :foo end

···

On Tue, Aug 31, 2004 at 03:20:04PM +0900, Gavin Sinclair wrote:

  X.foo # -> NameError: undefined method `foo' for X:module [1]

Please write the code in the placeholder.

[1] Or 'NoMethodError'; I can't tell which is which.

          =============

--
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com