JSONのパースしたときにキーがSymbolじゃなくて困ったのでメモ。 railsだとHash#symbolize_keysがあるけど、rails無しで。 def symbolize_keys(hash) hash.map{|k,v| [k.to_sym, v] }.to_h end hash = {'key':'value', 'key2':'value2'} symbolize_keys(hash) #=> {:key=>"value", :key2=>"value2"} Array#to_hはRuby 2.1からの機能なので古い環境では動きません。 hash.inject({}){|h, (k, v)| h[k.to_sym] = v; h}みたいにするといいかも。 追記: コメントで教えていただきました。 Hash#.[]を使ってHash[ h.map{|k,v| [k.to_sy