Created
June 28, 2011 15:50
-
-
Save pnc/1051447 to your computer and use it in GitHub Desktop.
Ruby blocks and required parentheses
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 group(symbol, &block) | |
block.call | |
end | |
symbol = :cheese | |
# Simple argument-and-block form: | |
group symbol do | |
puts "hello" | |
end # => "hello" | |
# Which you'd think could be flattened into this: | |
group symbol { puts "hello" } # => undefined method `symbol' | |
# But really you need: | |
group(symbol) { puts "hello" } # => "hello" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment