You were walking into a science experiments lab, when suddenly you’re bitten by a radioactive spider. The next day you wake up feeling weird until you realised you’re given superpowers by that bite. You could control the way you position yourself in your hierarchical family tree! So you could make yourself your father’s father (basically your grandfather…), isn’t that amazing?!?

Well that’s not a real superpower, but that’s what happens when you use the ruby prepend method when handling a modules.

Wait…

One of the first things that we learn in ruby is that everything inherits from Object , and that’s totally true but the caveat here is what lies between our class and Object . Lets see the following code:

class SomeClass

end SomeClass.ancestors

=> [SomeClass, Object, Kernel, BasicObject]

With this example we prove that our previous assumption was right. But what will happen when we add a module to that class?

module SomeModule

end class SomeClass

include SomeModule

end

Will the hierarchy change? Where will the module be? So this is how the hierarchy looks like:

SomeClass.ancestors

=> [SomeClass, SomeModule, Object, Kernel, BasicObject]