Forum: Ruby Re: I have some problem with convert to symbol, in Hash obje

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6087a044557d6b59ab52e7dd20f94da8?d=identicon&s=25 Peña, Botp (Guest)
on 2006-04-27 11:27
(Received via mailing list)
John:

# I want to convert "name" to :symbol
#   "name"=>"Ilyas store"   ---> :name => "Ilyas store"

sample only,

irb(main):039:0* h1={"fax"=>"80233923293", "name"=>"Ilyas store"}
=> {"name"=>"Ilyas store", "fax"=>"80233923293"}
irb(main):045:0* h2 = {}
irb(main):046:0> h1.each do |k,v|
irb(main):048:1>    h2[k.to_sym] = v
irb(main):049:1> end
irb(main):054:0> h2
=> {:fax=>"80233923293", :name=>"Ilyas store"}

kind regards -botp
This topic is locked and can not be replied to.