diff options
author | dblock <dblock@dblock.org> | 2014-03-30 20:25:03 -0400 |
---|---|---|
committer | dblock <dblock@dblock.org> | 2014-03-30 20:25:03 -0400 |
commit | 20733c83cb489b33ded89f535786601930067a1d (patch) | |
tree | 9cd9d8caf0d3915bc3583612173269980c66b06c /lib/hashie/hash.rb | |
parent | e1256f9a687f2e411d832514b8d12673ba79277b (diff) | |
parent | 4302d2de94df61e5bb12e8076e1108f2dd641e17 (diff) | |
download | hashie-20733c83cb489b33ded89f535786601930067a1d.tar.gz |
Merged.
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 43ff6c9..164b0ae 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(options) : array_object) + out[assignment_key] << (Hash === array_object ? array_object.to_hash(options) : array_object) end else - k = options[:symbolize_keys] ? k.to_sym : k.to_s - out[k] = Hash === self[k] ? self[k].to_hash(options) : self[k] + out[assignment_key] = Hash === self[k] ? self[k].to_hash(options) : self[k] end end out |