2009/6/29 Brian Candler <b.candler / pobox.com>: > Catsquotl wrote: >> Say the array holds members for 2007, 2008, 2009 >> i`d like to iterate through the full_array and map all members from 2008 >> in an array. > > Sounds like what you want is a Hash, not an Array. Something like: > As others will probably point out, this pattern can be simplified a bit. Since you asked... :-) year_to_members = Hash.new {|h,k| h[k] = []} members.each do |mem| year_to_members[mem.date.year] << mem end > The fundamental point is, you don't want to create "names of variables" > for each year - even though that is technically possible, as others may > also point out. The right thing to do is to build a Hash, which is an > object which associates a key (a year number) with a value (an array of > transaction objects). 100% agree. It is definitively a bad idea to create variables with the year in their name. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/