RailsCasts Pro episodes are now free!

Learn more or hide this

Swards's Profile

GitHub User: swards

Site: http://www.swards.net/

Comments by Swards

Avatar

Agreed - There's no need to use 'first' if you use index_by. The hash values are instances as expected.

Another option - use each_with_object

orders.each_with_object({}) { |o,hsh| hsh[o.purchased_at.to_date] = o.total_price }