Created
November 5, 2014 06:42
-
-
Save harrifeng/fcc6886d870c9d4a4864 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| ################################################################################################# | |
| # 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