Get hash key and convert into string ruby -



Get hash key and convert into string ruby -

example hash

hash = {:key => ["val1", "val2]}

when did on rails 3.0.7, fine.

> hash.keys.to_s => "key" > hash[hash.keys.to_s] => ["val1", "val2"]

but if rails 3.1.3, isn't.

> hash.keys.to_s => [\"key\"] > hash[hash.keys.to_s] => nil

is because of rails version changed? , is there other way turn hash key string works both version (or rails 2 too)?

did upgrade ruby rails? think alter between 1.8 , 1.9

try hash.keys.first.to_s (if there's 1 key) or hash.keys.join

ruby-on-rails-3

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -