Skip to content

Instantly share code, notes, and snippets.

@harrifeng
Created November 5, 2014 06:42
Show Gist options
  • Select an option

  • Save harrifeng/fcc6886d870c9d4a4864 to your computer and use it in GitHub Desktop.

Select an option

Save harrifeng/fcc6886d870c9d4a4864 to your computer and use it in GitHub Desktop.
#################################################################################################
# This is probably the most tricky one - #
# {} is also syntax for blocks, but only when passed to a method OUTSIDE the arguments parens. #
# When you invoke methods without parens, ruby looks at where you put the commas to figure out #
# where the arguments end (where the parens would have been, had you typed them) #
#################################################################################################
1.upto(2) { puts 'hello' } # it's a block
1.upto 2 { puts 'hello' } # syntax error, ruby can't figure out where the function args end
1.upto 2, { puts 'hello' } # the comma means "argument", so ruby sees it as a hash - th
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment