I’m new to Ruby and was reading this post comparing a mixin to a C# interface. What is unclear to me is whether or not a method from the mixin can be redefined in the class which implements it.
For example, if I put include myMixin — which has a method toJSON — in a class MyClass, can I redefine toJSON in MyClass, or am I stuck with the behavior defined in myMixin?
For anyone with further interest, is that blog post a good source of information? Is it reasonable to compare a Ruby mixin to a C# interface?
methods defined in a class will always override methods mixed into that class through a module in Ruby
For example:
Regardless of when the module is included, the method
bardefined on the class will be called first. This is because of how ruby looks up methods – it searches the class itself before it searches any modules included into the class.http://anders.janmyr.com/2009/06/ruby-method-lookup.html
http://blog.rubybestpractices.com/posts/gregory/031-issue-2-method-lookup.html