[Ruby] Hash retrieval

●●● Problem ●●●

puts hash.keys
puts hash.values

When executing the above method

one
two
three
1
2
3

Please write the code to create the variable hash as displayed in the terminal using symbols.

●●● Answer ●●●

hash{one:1,two:2,three:3}

●●● Explanation ●●●

First of all, from the hash structure. The hash description method with a symbol is defined by adding a colon after the key.

{Key:value}

Also, for the hash object, get the hash key by setting "object.keys". Hash values can be obtained by setting "object.values".

(Example)
hash{one:1}Against

hash.keys ⇨ one
hash.values ⇨ 1

Therefore, the above answer is given.

Recommended Posts

[Ruby] Hash retrieval
Ruby Hash notes
[ruby] Double hash
Ruby double hash
hash
Hash
About the behavior of ruby Hash # ==
Extraction of "ruby" double hash * Review
[Ruby] Extracting double hash in array
Ruby learning 4
[Ruby] Array
Ruby learning 5
Ruby basics
Ruby Review 2
Ruby addition
Refactoring Ruby
Ruby learning 3
Ruby setting 2
Ruby problem ⑦
Ruby learning 2
[Ruby] Block
Refactoring Ruby
ruby calculator
Ruby learning 6
Ruby settings 1
Hash basics
Refactoring Ruby
Ruby basics
Ruby memo
Ruby learning 1
Ruby Review 1
[Ruby] Module
AtCoder ABC127 D hash to solve with Ruby 2.7.1