How can I optimize this array.each in ruby?
I'm trying to optimize this bit of code and I thought I'd throw it out here to see if anyone has any ideas. I've been testing the performance using `Benchmark.measure {...}` and wrapping the entire function.

Yes, the item has a date that is a Ruby `Date`

      puts Benchmark.measure {
        grouped_items
      }

      def grouped_items
        unless @grouped
          @grouped = {}
          @items.each do |item|
            key = item.date
            if @grouped.has_key?(key)
              @grouped[key] << item
            else
              @grouped[key] = [item]
            end
          end
        end
        @grouped
      end

Thanks for any insight you care to share.
How can I optimize this array.each in ruby?
===

I'm trying to optimize this bit of code and I thought I'd throw it out here to see if anyone has any ideas. I've been testing the performance using `Benchmark.measure {...}` and wrapping the entire function.

Yes, the item has a date that is a Ruby `Date`

      puts Benchmark.measure {
        grouped_items
      }

      def grouped_items
        unless @grouped
          @grouped = {}
          @items.each do |item|
            key = item.date
            if @grouped.has_key?(key)
              @grouped[key] << item
            else
              @grouped[key] = [item]
            end
          end
        end
        @grouped
      end

Thanks for any insight you care to share.