Created
January 6, 2015 16:20
-
-
Save rklemme/d7455daff2ca88175ece to your computer and use it in GitHub Desktop.
Test different handling of return in lambda, proc and Proc.new
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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