J
Joe Van Dyk
I thought for all of five seconds for a good subject line for this
question, but failed. Sorry!
I have a string like:
"some_key: blah, some_other_key: more_blah, yet_other_key: yet_more_blah"
I want to build up a hash like
{ :some_key =3D> "blah", :some_other_key =3D> "more_blah", :yet_other_key
=3D> "yet_more_blah" }
And I don't really want to have to know what the possible keys are in advan=
ce.
So, the message format looks like:
<key>: <value>, <key>: <value>
How can I properly extract it out?
Here's my initial attempt, which works, but seems hackish:
attributes =3D message.split(",")
attributes.each do |attribute|
key, value =3D attribute.scan(/(\w+): (.+)/)[0]
result_hash[key.to_sym] =3D value.strip=20
end
=20
Also, this will get ran potentially thousands of times per second, so
executation speed is of some concern.
question, but failed. Sorry!
I have a string like:
"some_key: blah, some_other_key: more_blah, yet_other_key: yet_more_blah"
I want to build up a hash like
{ :some_key =3D> "blah", :some_other_key =3D> "more_blah", :yet_other_key
=3D> "yet_more_blah" }
And I don't really want to have to know what the possible keys are in advan=
ce.
So, the message format looks like:
<key>: <value>, <key>: <value>
How can I properly extract it out?
Here's my initial attempt, which works, but seems hackish:
attributes =3D message.split(",")
attributes.each do |attribute|
key, value =3D attribute.scan(/(\w+): (.+)/)[0]
result_hash[key.to_sym] =3D value.strip=20
end
=20
Also, this will get ran potentially thousands of times per second, so
executation speed is of some concern.