Ruby Procs and their execution context

I had a problem just now which involved creating a proc in one class, and executing it in the context of a different class. I pondered the problem for a little while, did a little research, and then realized the obvious solution would be to pass the current self into the proc.

Example:

stuff = lambda do |context, thing|
  context.some_method(thing)
end

Thought I might save someone the trouble of thinking of that somewhat obvious solution.

posted 1 year ago on November 4th, 2010 at 17:59 /