Procs, Lambdas and closure.

Posted by Sergey Enin 29 August 2011 at 22:13

We are all use blocks in our ruby programs, but what if we`d like to store somewhere or pass anonymous code to some method. 

It is neccessary to do for example in Strategy pattern, where

1) we are defining or load some strategies;

2) we are passing one of strategy to object to call some action;

 

For that purpose Proc and lambda are very usefull.

Posted in ,  | Tags , , , , , , , ,