RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: swards
Site: http://www.swards.net/
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 }
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