I was playing around with include and extend today and found something I don’t quite understand.
module Dragon
def roar
'roar'
end
end
module Knight
include Dragon
def fight
'fight'
end
end
class Other
extend Knight
end
puts Other.roar # -> 'roar'
Why is it that roar is available as a class method on Other? I did extend Knight which makes Knight's methods available as class methods. Knight in turn will include Dragon but that should make the Dragon methods available as instance methods. But that’s not the only weird thing going on here, you also can’t create instances of modules so why is it that I can include on a module?
1) You include methods from Dragon module into Knigth module (like mixin).
2) When u extend class, all methods from Knight (Dragon methods have been already included) become class methods of class Other. It is normal behaviour, don’t see a problem.
Another question what do u want to achieve?