Last active
May 30, 2019 03:19
-
-
Save grohiro/d85f3cd02f9cb7f3b634a44bd2c063fb to your computer and use it in GitHub Desktop.
Hash argument of Ruby
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
| require 'json' | |
| def print_json(data) | |
| puts JSON.dump(data) | |
| end | |
| print_json(1) #=> 1 | |
| print_json([1]) #=> [1] | |
| print_json({a:1}) #=> {"a":1} | |
| print_json({a:1, b: 2}) #=> {"a":1,"b":2} | |
| print_json 1 #=> 1 | |
| print_json [1] #=> [1] | |
| #print_json {a: 1} #=> syntax error | |
| #print_json {a: 1, b: 2} #=> syntax error | |
| print_json a: 1 #=> {"a":1} | |
| print_json a: 1, b: 2 #=> {"a":1,"b":2} | |
| # why? | |
| print_json [1] #=> OK | |
| print_json({a: 1}) #=> OK | |
| #print_json {a: 1} #=> NG | |
| print_json a: 1 #=> OK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment