G
Gavin Sinclair
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
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