diff options
author | Florian Frank <flori@ping.de> | 2012-10-02 16:27:29 +0200 |
---|---|---|
committer | Florian Frank <flori@ping.de> | 2012-10-02 16:27:29 +0200 |
commit | 01a5165bee5c8cf199e37b3ccc90f1f824d41783 (patch) | |
tree | a2cf69fe876ebf0b236d09af683c640b205c34ce /lib/json/generic_object.rb | |
parent | 2d2b921fe1396b75dcb0f624021fb20062c68600 (diff) | |
download | json-generic-from_hashes.tar.gz |
Renamed method and handle arraysjson-generic-from_hashes
Diffstat (limited to 'lib/json/generic_object.rb')
-rw-r--r-- | lib/json/generic_object.rb | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/json/generic_object.rb b/lib/json/generic_object.rb index 636ea33..cd93e1a 100644 --- a/lib/json/generic_object.rb +++ b/lib/json/generic_object.rb @@ -11,16 +11,19 @@ module JSON self[data] end - def from_hashes(hash) - result = new - hash.to_hash.each do |key, value| - if value.respond_to?(:to_hash) - result[key] = from_hashes(value) - else - result[key] = value + def from_hash(object) + case + when object.respond_to?(:to_hash) + result = new + object.to_hash.each do |key, value| + result[key] = from_hash(value) end + result + when object.respond_to?(:to_ary) + object.to_ary.map { |a| from_hash(a) } + else + object end - result end end |