Skip to content

Instantly share code, notes, and snippets.

@pnc
Created June 28, 2011 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pnc/1051447 to your computer and use it in GitHub Desktop.
Save pnc/1051447 to your computer and use it in GitHub Desktop.
Ruby blocks and required parentheses
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