Create an array of hashes : Array.new « Array « Ruby






Create an array of hashes


a = Array.new(2, Hash.new)
a[0]['cat'] = 'feline'
p a  
a[1]['cat'] = 'Felix'
p a 

 








Related examples in the same category

1.Array with Array.new
2.Array.new creates an empty array
3.Array.new(2) creates an array with two nil values
4.Array.new(5, "A") fills an array with five a
5.Fill an array of hashes
6.Array initialized by copying