Skip to content

Instantly share code, notes, and snippets.

@rklemme
Created January 6, 2015 16:20
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 rklemme/d7455daff2ca88175ece to your computer and use it in GitHub Desktop.
Save rklemme/d7455daff2ca88175ece to your computer and use it in GitHub Desktop.
Test different handling of return in lambda, proc and Proc.new
class X
def initialize
@l = lambda { return 123 }
@p = proc { return 456 }
@o = Proc.new { return 789 }
end
def l; @l.call end
def p; @p.call end
def o; @o.call end
end
x = X.new
begin
puts "lambda"
puts x.l
rescue Exception => e
puts "ERROR: #{e}"
end
begin
puts "proc"
puts x.p
rescue Exception => e
puts "ERROR: #{e}"
end
begin
puts "Proc.new"
puts x.o
rescue Exception => e
puts "ERROR: #{e}"
end
$ ruby -v
ruby 2.0.0p598 (2014-11-13) [x86_64-cygwin]
$ ruby proc-return.rb
lambda
123
proc
ERROR: unexpected return
Proc.new
ERROR: unexpected return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment