talk: super: no superclass method talk (NoMethodError)
when I override a method that already exists?Here is the sample code I'm using
class Foo
def talk(who, what, where)
p "#{who} is #{what} at #{where}"
end
end
Foo.new.talk("monster", "jumping", "home")
class Foo
define_method(:talk) do |*params|
super(*params)
end
end
Foo.new.talk("monster", "jumping", "home")
It's not working because you overwrite #talk. Try this
class Foo
def talk(who, what, where)
p "#{who} is #{what} at #{where}"
end
end
Foo.new.talk("monster", "jumping", "home")
class Bar < Foo
define_method(:talk) do |*params|
super(*params)
end
end
Bar.new.talk("monster", "table", "home")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With