From: GOTO Kentaro Date: 2008-07-12T12:27:10+09:00 Subject: Re: inject idiom Hi Ömer, On Sat, Jul 12, 2008 at 3:49 AM, عمر ملقب بالثانی wrote: > I wonder what the best practice is? The most readable and best suited to > Ruby-style of programming. In Perl, although there is more than one way > to do every thing you want, there are definitely best practices. What > about Ruby? How do one use the inject idiom best? Do you like this? doc = Hpricot(open("http://del.icio.us/")) tags = doc.search("//div.hotlist/ol/li").inject({}){|hash,entry| hash[entry.search("h4/a[1]").first['href']] = entry.search("div/ul/li/a/*").to_a hash } I sometimes want a hash setter method returning the hash itself: class Hash def set(key, value) self.store(key, value) return self end end HTH, -- Gotoken