I have some problem with convert to symbol, in Hash object


#1

I use it functionality:

Hash[str.scan(/store[([^\s,]+)\s]=\s*([^,]+)/).flatten]
=> {“fax”=>“80233923293”, “name”=>“Ilyas store”,
“description”=>“lkjklsdaj”, “phone”=>“4999-233-2923”}

The problem with covert string to symbol.

I want to convert “name” to :symbol
“name”=>“Ilyas store” —> :name => “Ilyas store”


On Apr 26, 2006, at 7:12 AM, Jonh wrote:

if params[:param]
paramater = Hash.new
for value in params[:param].split(/,/)
if value =~ /(.)=(.)/
parameter[$1] = $2
end
end
end
puts parameter.inspect

Does this help?

str = “store[name]=Ilyas store,store[phone]= 4999-233-2923, store
[fax]= 80233923293,store[description]=lkjklsdaj,save=save,cancel=cancel”
=> “store[name]=Ilyas store,store[phone]= 4999-233-2923, store[fax]=
80233923293,store[description]=lkjklsdaj,save=save,cancel=cancel”

Hash[str.scan(/([^\s,]+)\s=\s*([^,]+)/).flatten]
=> {“cancel”=>“cancel”, “store[fax]”=>“80233923293”, “store
[name]”=>“Ilyas store”, “save”=>“save”, “store
[description]”=>“lkjklsdaj”, “store[phone]”=>“4999-233-2923”}

James Edward G. II


#2

2006/4/27, John removed_email_address@domain.invalid:

I use it functionality:

Hash[str.scan(/store[([^\s,]+)\s]=\s*([^,]+)/).flatten]
=> {“fax”=>“80233923293”, “name”=>“Ilyas store”,
“description”=>“lkjklsdaj”, “phone”=>“4999-233-2923”}
The problem with covert string to symbol.

I want to convert “name” to :symbol
“name”=>“Ilyas store” —> :name => “Ilyas store”

Difficult to test without the original string but try something like
this:

Hash[str.scan(/store[([^\s,]+)\s]=\s*([^,]+)/).map{|k, v|
[k.to_sym,v]}.flatten]

Kind regards

robert