mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-04-26 15:13:56 +00:00
[ruby/en] clarify alternate hash syntax
This commit is contained in:
parent
572827b39f
commit
350dd22db2
@ -233,11 +233,14 @@ hash['number'] #=> 5
|
||||
# Asking a hash for a key that doesn't exist returns nil.
|
||||
hash['nothing here'] #=> nil
|
||||
|
||||
# When using symbols for keys in a hash, you can use an alternate syntax.
|
||||
# When using symbols for keys in a hash, you can use an alternate syntax similar
|
||||
# to JavaScript.
|
||||
|
||||
# key => value
|
||||
hash = { :defcon => 3, :action => true }
|
||||
hash.keys #=> [:defcon, :action]
|
||||
|
||||
# key: value
|
||||
hash = { defcon: 3, action: true }
|
||||
hash.keys #=> [:defcon, :action]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user