Re:How Ruby Borrowed a Decades Old Idea From Lisp
by majormajor on Tuesday September 18, 2012 @12:22PM
(#4538934)
For DSL/metaprogramming fun (and occasional hair-pulling, heh), Ruby also gives you instance_eval and its siblings/cousins for running a block with "self" bound to a different object. I've mainly used it for providing the ability to run a block in the scope of a certain object without the author of the block having to reference that object at all (so field names can be referred to without any prefix, which gives a nice clean syntax).
[ Parent
| on HN ]
Re:How Ruby Borrowed a Decades Old Idea From Lisp
by pat_shaughnessy on Tuesday September 18, 2012 @12:31PM
(#4538975)
Yup - I'm planning to cover that later in the same chapter in my eBook. Your description is perfect: it's a closure with the "self" redirected to a different object (the receiver of instance_eval).