James Gray
1/3/2006 10:52:00 PM
On Jan 3, 2006, at 4:41 PM, Joe Van Dyk wrote:
> IMO, my version's more readable. I'm going for readability here.
def process_string str
result = Hash.new
str.scan(/^\s*(important ([a-zA-Z0-9]+): .+?)\s*$/) do |line, key|
result[key] = line
end
result
end
# ... or ...
def process_string str
str.inject(Hash.new) do |result, line|
result[$1] = line if line =~ /^\s*important ([^:]+):/
result
end
end
James Edward Gray II