Skip to content

Instantly share code, notes, and snippets.

@chuckremes
Created October 20, 2011 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuckremes/1301471 to your computer and use it in GitHub Desktop.
Save chuckremes/1301471 to your computer and use it in GitHub Desktop.
# Examples 9 & 10 from http://innig.net/software/ruby/closures-in-ruby.rb
def f(closure)
puts
puts "About to call closure"
result = closure.call
puts "Closure returned: #{result}"
"Value from f"
end
begin
f(Proc.new { return "Value from Proc.new" })
rescue Exception => e
puts "Failed with #{e.class}: #{e}"
end
Chuck-Remess-Mac-Pro:ruby cremes$ rvm default
Chuck-Remess-Mac-Pro:ruby cremes$ ruby -v
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.5.0]
Chuck-Remess-Mac-Pro:ruby cremes$ ruby closure_crash.rb
About to call closure
Failed with LocalJumpError: unexpected return
Chuck-Remess-Mac-Pro:ruby cremes$ rvm system
Chuck-Remess-Mac-Pro:ruby cremes$ rbx -v
rubinius 2.0.0dev (1.8.7 a9d31fef yyyy-mm-dd JI) [x86_64-apple-darwin10.8.0]
Chuck-Remess-Mac-Pro:ruby cremes$ rbx closure_crash.rb
About to call closure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment