diff options
Diffstat (limited to 'lib/hashie/hash.rb')
-rw-r--r-- | lib/hashie/hash.rb | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/hashie/hash.rb b/lib/hashie/hash.rb index c36bb91..35d660c 100644 --- a/lib/hashie/hash.rb +++ b/lib/hashie/hash.rb @@ -7,19 +7,19 @@ module Hashie class Hash < ::Hash include HashExtensions - # Converts a mash back to a hash (with stringified keys) + # Converts a mash back to a hash (with stringified or symbolized keys) def to_hash(options={}) out = {} keys.each do |k| + assignment_key = k.to_s + assignment_key = assignment_key.to_sym if options[:symbolize_keys] if self[k].is_a?(Array) - k = options[:symbolize_keys] ? k.to_sym : k.to_s - out[k] ||= [] + out[assignment_key] ||= [] self[k].each do |array_object| - out[k] << (Hash === array_object ? array_object.to_hash : array_object) + out[assignment_key] << (Hash === array_object ? array_object.to_hash : array_object) end else - k = options[:symbolize_keys] ? k.to_sym : k.to_s - out[k] = Hash === self[k] ? self[k].to_hash : self[k] + out[assignment_key] = Hash === self[k] ? self[k].to_hash : self[k] end end out |