I’m still learning Ruby and I have a question concerning hash of hashes. The hash bellow is what I would like to access :
reserved_instance_price = [
'us-east-1' => ['t1.micro' => 0.02, 'm1.small' => 0.08, 'm1.medium' => 0.160 ],
'us-west-1' => ['t1.micro' => 0.02, 'm1.small' => 0.08, 'm1.medium' => 0.160 ],
'eu-west-1' => ['t1.micro' => 0.02, 'm1.small' => 0.085, 'm1.medium' => 0.170 ]
]
My questions: Is it the right way to implement hashes of hashes in ruby ? and how to access a particular value ?
Thank you
[]syntax is for arrays. To construct hashes use{}Your example becomes
For accessing a particular value simply do
reserved_instance_price['us-east-1']['t1.micro']which will return0.02If you would like your indexes to be symbols rather than string, you can also use the syntax
Access becomes