Removing "warning: method redefined"

B

Brian Takita

Hello,

What is the best way to remove "warning: method redefined" warnings?

Thank you,
Brian Takita
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: Removing "warning: method redefined""

|What is the best way to remove "warning: method redefined" warnings?

$VERBOSE=nil or remove method first by using remove_method.

matz.
 
B

Brian Takita

Thank you for your help.

I would like to keep the warnings on, so I don't see $VERBOSE=nil as a
viable option.

remove_method works for me except when I need to call the super method
in the new definition.

Is there another way to get rid of the warning or to use remove_method
and still be able to use the super method?
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: Removing "warning: method redefined""

|remove_method works for me except when I need to call the super method
|in the new definition.

warning and remove_method are not related with super. IIRC, warning
was caused when you replace an existing method without making any
alias to the original.

class Foo
def foo
p :foo
end
end
class Bar < Foo
def foo
end
# warning
def foo
end
# remove foo in Bar
remove_method :foo
# no warning
def foo
super # calls foo in Foo
end
end
Bar.new.foo

matz.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top