From: Joe Van Dyk Date: 2006-01-04T07:41:18+09:00 Subject: Re: silly regex question On 1/3/06, James Edward Gray II wrote: > On Jan 3, 2006, at 4:22 PM, Joe Van Dyk wrote: > > > Can someone help me make this code not suck? > > I guess it depends on what you mean by that... > > > require 'test/unit' > > > > # EWWWWWWW > > def process_string str > > result = Hash.new > > str.to_a.each do |line| > > line.scan(/important ([a-zA-Z0-9]+): /) do |key| > > result[key.first] = line > > end > > end > > result > > end > > def process_string str > Hash[*str.scan(/^\s*(important ([a-zA-Z0-9]+): .+) > $/).flatten.reverse] > end IMO, my version's more readable. I'm going for readability here.