module A; end
module B; end
class C; end
class D < C; end
d = D.new
D.send(:include, A)
d.extend(B)
d_meta = class << d; self; end
d.class.ancestors
=> [D, A, C, Object, Kernel, BasicObject]
d_meta.ancestors
=> [B, D, A, C, Object, Kernel, BasicObject]
and to me, benefits of composition over inheritance is that it doesn't modify object dispatch hierarchy.
PS: pls comment here.
Well, the statement was "it's a good hack, but bad practice".
Works fine on small scopes, but once grows it becomes harder to read thus understand the code, given this as a normal practice.
Debugging is hard because it's not quite obvious why it's doing one thing instead of another and that's only because at some point of call stack an object got extended with a module.
Don't get me wrong, it works. But at certain point it's like "magic" )
well, that's how you start! ;)