So found this out the hard way trying to use modules to overload instance methods in classes.
So if you have something like the code listed below, the module will never execute the test method.
module Mixin
def test
puts "i am in the module"
end
end
class Example
include Mixin
def test
puts "i am in the class"
end
end
This is because when you mix in a module, it’s listed as an ancestor. So when ruby looks for the object to answer the message, it first looks in the class, finds the method, and says job done. It never reaches the module.
For example:
>> Example.ancestors
=> [Example, Mixin, Object, Kernel]
This means that to do things like using a module to overload how an object is converted to yaml you have to crack open the meta-class and do your work there.