Created
August 15, 2012 19:26
-
-
Save nelhage/3362824 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def callblock (&block) | |
block.call | |
puts "block.call returned normally" | |
end | |
def yieldblock (&block) | |
yield | |
puts "yield returned normally" | |
end | |
def test_call_block | |
callblock do | |
puts "test_call_block" | |
return | |
end | |
end | |
def test_yield_block | |
yieldblock do | |
puts "test_yield_block" | |
return | |
end | |
end | |
def test_call_lambda | |
callblock &(lambda do | |
puts "test_call_lambda" | |
return | |
end) | |
end | |
def test_yield_lambda | |
yieldblock &(lambda do | |
puts "test_yield_lambda" | |
return | |
end) | |
end | |
test_call_block | |
test_yield_block | |
test_call_lambda | |
test_yield_lambda | |
# Output: | |
# | |
# test_call_block | |
# test_yield_block | |
# test_call_lambda | |
# block.call returned normally | |
# test_yield_lambda |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment