Created
August 11, 2011 18:30
-
-
Save mjackson/1140365 to your computer and use it in GitHub Desktop.
Demonstrates the difference between Ruby's two different block styles.
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
def a(*args, &block) | |
puts "a got a block" if block_given? | |
end | |
def b(*args, &block) | |
puts "b got a block" if block_given? | |
end | |
# In this call, `b' is called with the block and the | |
# return value is given to `a' as an argument. | |
a b {} | |
# In this call, `a' gets the result of `b' *and* the block. | |
a b do | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To clarify, mjijackson is showing that teh Ruby parser binds
{}
more tightly than parameters, which bind more tightly thando...end
. Excellent example!