Alle giovedì 10 gennaio 2008, botp ha scritto:
i mean will undef_ do a remove or what?
but anyway, that is cool Stefano. thanks for the new i’ve just learned.
kind regards -botp
Well, in general remove_method will remove it only from the class where
called. If a superclass defines the same method, the superclass’s method
be called. According to ri, instead, undef_method, prevents the class
responding to the method at all. Here’s an example showing the
puts “test for class A”
class B < A
puts “test for class B”
b = B.new
=> test for class B
=> test for class A
=> undefined method `test’ for #<B:0xb7c9a754> (NoMethodError)
In my previous post, used undef_method instead of remove_method thinking
(without trying it) that remove_method would only remove it from the
singleton class. I tried it now, and I saw it works with both methods.
seems singleton classes are treated in a different way.