Ruby - Hashes Within Hashes

Introduction

You can have hashes within hashes.

Demo

people = { 
 'xml' => { # w w w.ja va2s .  co m
     'name' => 'XML', 
     'age' => 3, 
     'gender' => 'male', 
     'favorite painters' => ['Java', 'C', 'C++'] 
 }, 
 'json' => { 
     'name' => 'JSON', 
     'age' => 5, 
     'gender' => 'female' 
 } 
} 

puts people['xml']['age'] 
puts people['json']['gender'] 
p people['json'] 

puts people['xml']['favorite painters'].length 
puts people['xml']['favorite painters'].join(", ")

Result

Related Topic