# coding: utf-8 i = 0 increment_function = lambda do puts "Incrementing from #{i} to #{i+1}" i += 1 end decrement_function = lambda do i -= 1 puts "Decrementing from #{i+1} to #{i}" end increment_function.call decrement_function.call increment_function.call increment_function.call decrement_function.call =begin From the book, Ch.8 page 217 (p. 240 of the PDF): Each block you pass to the lambdas accesses the same variable in the parent scope. Ruby achieves this by checking whether the EP already points to the heap. If so, as with the second call to lambda in Listing 8-15, Ruby won’t create a second copy; it will simply reuse the same rb_env_t structure in the second rb_proc_t structure. Ultimately, both lambdas use the same heap copy of the stack. Suggestion: find the code responsible for this logic in the actual Ruby source! =end