From: Devin Mullins Date: 2005-07-02T08:22:35+09:00 Subject: Re: no clue Joe Van Dyk wrote: >Here's my initial attempt, which works, but seems hackish: > > attributes = message.split(",") > attributes.each do |attribute| > key, value = attribute.scan(/(\w+): (.+)/)[0] > result_hash[key.to_sym] = value.strip > end > > Slightly more readable: result_hash = {} attributes = message.split(",") attributes.each do |attribute| key, value = *attribute.match(/(\w+): (.+)/).captures result_hash[key.to_sym] = value.strip end Yet more readable: result_hash = {} attributes = message.split "," attributes.each do |attribute| key, value = *attribute.split(": ",2) result_hash[key.to_sym] = value.strip end Not sure: attributes = message.split "," result_hash = attributes.inject {} do |hash,attribute| key, value = *attribute.split(": ",2) hash[key.to_sym] = value.strip hash end >Also, this will get ran potentially thousands of times per second, so >executation speed is of some concern. > > No clue. Devin