Prototype

I’m reading a paper called [Metaprogramming in Ruby – A Pattern Catalog] by Sebastian Gunther and Marco Fischer. They gave some code example, that I did not understand properly in the beginning. Hence, this post aims to clarify the mystery of those lines.

This part of code is from Figure 11, the implementation of Prototype module and its usage inside Hydra class. I modified the code to add some output to see how the code is executed.

When we include a module Prototype in a class, we can see the execution. The function included is called when Prototype is included in Hydra. Inside that function, the class_eval and instance_eval do their jobs. `

class Hydra
include Prototype
end
===> We get
Prototype included in Hydra
Hydra.class_eval is called
Hydra.instance_eval is called