Skip to content

Instantly share code, notes, and snippets.

@nelhage
Created August 15, 2012 19:26
Show Gist options
  • Save nelhage/3362824 to your computer and use it in GitHub Desktop.
Save nelhage/3362824 to your computer and use it in GitHub Desktop.
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