Consider a code from this article:
class Coffee
def cost
2
end
end
module Milk
def cost
super + 0.4
end
end
module Sugar
def cost
super + 0.2
end
end
coffee = Coffee.new
coffee.extend(Milk)
coffee.extend(Sugar)
coffee.cost # 2.6, while I expected 2.2
The reason why it's 2.6 and not 2.2 is because every call of extend
adds a module into the instance singleton class ancestors chain, as pointed out below.