I am reading the excellent The Ruby Way. I most probably not understand correctly the following pieces:
With include, the module's methods become available as instance methods; with extend, they become available as class methods
I have written the following code example:
puts 'module method'
im = IncludeModule.new
# IncludeModule.moduleMethod # this is correct
im.moduleMethod # module method becomes instance method
em = ExtendModule.new
ExtendModule.moduleMethod # module method becomes class method
em.moduleMethod # this is failing! WHY?
As pointed above the em#moduleMethod is failing. Being a class method I expect it to be available also on every instance. What I wrongly understood?
Later I can read the following:
The extend method will mix a module into an object. The instance methods from the module become instance methods for the object.
Isn't this in contradiction with the first quote?
Please enlighten me.