From: Rick DeNatale Date: 2009-02-19T02:11:40+09:00 Subject: Re: Hash acting weird with scRUBYt --0016362836445fe37f04633483d1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Wed, Feb 18, 2009 at 11:59 AM, Rob Biedenharn wrote: > > On Feb 18, 2009, at 8:21 AM, Rick DeNatale wrote: > > On Tue, Feb 17, 2009 at 7:58 PM, Patrick L. wrote: >> >>> >>> Here's the new code: http://pastie.org/392399 >>> And here's the new error: http://pastie.org/392397 >>> >>> >> Some comments. >> >> ... >> Ok, that said,if you inspect what the next line is actually returning: >> >> url_hash = istock_data.to_hash >> p url_hash >> >> You should see something like: >> >> >> [{:url=>"/file_closeup/nature/nature-backgrounds/8546665-foggy-lane-with-trees.php?id=8546665"}, >> > .... > >> {}, {}, {}, {}, {}, {}, {}] >> >> Which is an array of hashes. The fetch call is looking for a string >> containing the url to be fetched. >> >> So, instead you need to take another approach, and >> 1) extract the url from each hash, >> 2) Scrape each individual url, and collect the results. >> >> Something like: >> >> http://pastie.org/392796 >> >> > And Rick's step 1 gets the hint: > array_of_url_values_as_strings = \ > array_of_hashes_with_url_keys.map {|h| h[:url]} Which is more the way I'd write this code myself than my pastie example. I've got a tendency to write more verbose, step by stuff code when I'm trying to help someone in order to get the point across, or in some cases when I'm thinking a problem through myself. If I do this last, I typically refactor the code to make it tighter as another step. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale --0016362836445fe37f04633483d1--