I have recently seen some code that I do not completely understand. There is an array named foo that contains instances of Proc objects. Then, an env object is used to setup an environment to work in:
env = Object.new
foo.each do |f|
env.instance_eval &f # what happens here?
end
What exactly happens when you open the object with instance_eval and pass &f as an argument? What happens to env at this point and the Proc itself?
The Proc gets executed in the context of
env. It is as if you are calling a method onenv: the block has access to its instance variables and public and private methods.