Answer the question
In order to leave comments, you need to log in
[Ruby on Rails] how to override parent method?
I want to patch up one method in the gem to fit my needs. I have little experience in OOP and do not quite understand how to override the parent method so that when this method is called, mine is called? Or is it just forking the gem and editing directly?
Answer the question
In order to leave comments, you need to log in
You can rediscover the class in your code and rewrite the method.
But this is the wrong approach.
This method is probably in some module.
As an idea, you can do:
module GemModule do
class GemModuleCass << SomeOtherClass
def method
...
end
end
GemModule::GemClass.class_eval do
def method
...
end
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question