From: Tim Bray Date: 2007-07-10T23:49:35+09:00 Subject: Re: Beautiful Code : Pity he didn't ask here... On Jul 10, 2007, at 5:11 AM, Daniel Martin wrote: > As James said, I'm going to have to disagree on this, though I'd clean > it up to: > > article_pattern = \ > %r{GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+) } > ARGF.each_line do |line| > line.scan(article_pattern) do |article,| > puts article > end > end > > Look, no global variables! Yep, much better, I wish I'd done it that way. > I agree with your use of Hash.new(0), but disagree that it's mere > personal preference - it's much more common to use even the single > argument form in the constructor than to use default=. Why? default= makes it more obvious what you're doing. I think it's better practice. >> Example 4.5 looks like a poster child for the Hash.new block >> approach... > > Agreed. I wonder if perhaps he's spent more time in python or some > other dynamic language than Ruby. Perl :) -Tim