From: 7stud -- Date: 2011-04-21T03:15:41+09:00 Subject: Re: using hash keys as object name Neubyr Neubyr wrote in post #993923: > How do I assign hash's key as an object name? For example I have a hash > as: > > fruits = {"apple" => ["green", "red"], "melons" => ["water", "musk"] } > > I would like to create a File or String objects by reading above hash, > something like > > fruits.keys.each {|k| "#{k}" = String.new} > > Any hints or suggestions on how to do this will be really helpful. > > thanks, > neuby. fruits = {"apple" => ["green", "red"], "melons" => ["water", "musk"] } h = {} fruits.keys.each do |key| h[key] = "" end p h --output:-- {"apple"=>"", "melons"=>""} h['apple'] = 10 p h --output:-- {"apple"=>10, "melons"=>""} --output:-- -- Posted via http://www.ruby-forum.com/.