From: RichardOnRails Date: 2009-12-12T01:35:07+09:00 Subject: Re: Fill gaps in Array of Hashes This is a little cleaner. with the same result: # Aldric Giacomoni's neat solution, modified slightly require 'rubygems' require 'activesupport' # What? I'm lazy. to_date is damn handy. array = [ {:positive=>"0", :neutral=>"2", :total=>"5", :date=>"2009-12-01", :negative=>"3"}, {:positive=>"3", :neutral=>"3", :total=>"7", :date=>"2009-12-09", :negative=>"1"}, {:positive=>"1", :neutral=>"1", :total=>"3", :date=>"2009-12-05", :negative=>"1"} ] range = ("2009-12-01".to_date .. "2009.12.11".to_date) range.each { |date| next if array.find { |row| row[:date] == date.to_s} array << {:positive=>"0", :neutral=>"0", :total=>"0", :date=>date.to_s, :negative=>"1"} } sorted = array.sort { |r1, r2| r1[:date] <=> r2[:date] } sorted.each { |row| puts row.inspect} HTH, Richard