G
Geoff
So I'm looking to create a Hash from a string which is pretty much
formatted like you would create a hash:
theString = "foo=>1,bar=>2,baz=>'go fish'"
and i was wondering if anyone had any nice and simple ideas for how to
grab this out. I came up with a little way to do it but i was just
wondering if anyone out there can think of a shorter way.
Here's what i came up with:
login = Hash.new
theString.split(',').each {|pair| pair.match(/(.+)=>(.+)/);
login[$1.intern]=$2 }
formatted like you would create a hash:
theString = "foo=>1,bar=>2,baz=>'go fish'"
and i was wondering if anyone had any nice and simple ideas for how to
grab this out. I came up with a little way to do it but i was just
wondering if anyone out there can think of a shorter way.
Here's what i came up with:
login = Hash.new
theString.split(',').each {|pair| pair.match(/(.+)=>(.+)/);
login[$1.intern]=$2 }