●●● 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