code = <<__CODE__ def message_function str = "The quick brown fox" func = lambda do |animal| puts "\#{str} jumps over the lazy \#{animal}." end str = "The sly brown fox" # <-- str is written after the closure is created by lambda func end function_value = message_function function_value.call('dog') function_value.call('cat') function_value.call('badger') __CODE__ #RubyVM::InstructionSequence.compile(code).eval #puts RubyVM::InstructionSequence.compile(code).inspect puts RubyVM::InstructionSequence.compile(code).disasm =begin Compare this with the LISP version of the same logic: (defun message_func () (let ((str "The quick brown fox")) ; We can't do both str and func in the same LET, as func refers to str. ; a single LET* would work, though. (let ((func (lambda (animal) (print ; first argument of concatenate must be the return value's type (concatenate 'string str " jumped over the lazy " animal))))) (progn (setq str "The sly brown fox") func)))) (setq foo (message_func)) (funcall foo "dummy") Not surprisingly, LISP agrees with Ruby. =end