From: "ara.t.howard" Date: 2008-07-12T12:50:09+09:00 Subject: Re: inject idiom On Jul 11, 2008, at 12:49 PM, عمر ملقب بالثانی wrote: > doc = Hpricot( open("http://del.icio.us/") ) > tags = doc.search("//div.hotlist/ol/li").inject({}) do | hash, entry | > link = entry.search("h4/a").first['href'] > hash[link] = entry.search("div/ul/li/a").inject([]) do | list, tag | > list << tag.inner_html > end > hash > end i prefer doc = Hpricot( open("http://del.icio.us/") ) tags = doc.search("//div.hotlist/ol/li").inject({}) do | hash, entry | href = entry.search("h4/a").first['href'] list = entry.search("div/ul/li/a").map{|tag| tag.inner_html} hash.update href => list end . use space to give meaning: a newline is one char . use explicit var names as comments . try to minimize method chaining so stacktraces to line #42 have at least some meaning . use hash.update with inject because it returns self these things are religious i realize but, coming from perl, you understand. kind regards. a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama