February 2012
1 post
Creating an Array of Hashes in Ruby →
from Henry Cipolla’s blog:
I just made a simple mistake which I figure would be good share with anybody new-ish to Ruby. I wrote the following code to create an array of hashes and fill in some values. Can you guess what the output is?
#!/usr/bin/env ruby
testArray = Array.new(5, Hash.new) 0.upto(4) do |i| testArray[i][:value] = i end
0.upto(4) do |i| puts testArray[i][:value] end
...