From: Ashley Moran Date: 2006-06-23T04:47:22+09:00 Subject: Re: Turning an Array into a Hash based on an attribute value On Jun 22, 2006, at 8:25 pm, Simen Edvardsen wrote: > Hash[*self.map{|m|m.send(method).to_s.to_sym}.zip(self).flatten ] > Disclaimer: inject is probably more appropriate, but my solution at > least looks cooler ;) Simen... you don't come from a Perl background do you ;) On Jun 22, 2006, at 8:09 pm, Simon Kr�ger wrote: > class Array > def hash_on(method) > inject({}){|h, i| h.merge({i.send(method).to_s.to_sym, i})} > end > end I like! On Jun 22, 2006, at 8:05 pm, Louis J Scoras wrote: > I'm not sure of the api--i.e.: this is untested--but why not something > like this: > > particular_item = DataItem.find_by_identifer("my_identifier") > particular_item.do_something > > This is the sort of thing that databases are good at. It avoids hitting the database every time - if there are 500 items in the list I'd rather get them all out at once than hit the server 500 times. Thanks for the replies people. Incidentally... what is the convention here on CCing posters in replies? I come from the FreeBSD lists where it's normal to CC the poster so they don't have to check the list. But people on Ruby lists are really surprised when I do that.