Thomas Wieczorek
8/20/2008 12:22:00 PM
You can also create Structs in Ruby if you prefer them
Item = Struct.new(:title, :article_number)
it = Item.new("Wii", "Wii")
it.title #=>"Wii"
You can add as many members as you like in the Struct constructor.
As to go with your statistics, I agree with the others. I'd use a
statitiscs Hash and count the different items:
stats_hash = { }
Stats = Struct.new(:count, :sold)
item_array.each { |it|
unless hash[item[:article_number]]
hash[item[:article_number]] = Stats.new(0, 0)
end
hash[item[:article_number]].count += 1
hash[item[:article_number]].sold += 1 if item[:did_it_sell]
}