Sha256: e51108b0915b250d45b0be5c1f51ff2f699e1d1e29480b1759025bf02513cf40
Contents?: true
Size: 1.06 KB
Versions: 2
Compression:
Stored size: 1.06 KB
Contents
require "multi_json/vendor/okjson" unless defined?(::OkJson) module MultiJson module Engines class Okjson def self.decode(string, options = {}) #:nodoc: result = OkJson.decode(string) options[:symbolize_keys] ? symbolize_keys(result) : result end def self.encode(object) #:nodoc: OkJson.encode(stringify_keys(object)) end def self.symbolize_keys(object) #:nodoc: return object unless object.is_a?(Hash) object.inject({}) do |result, (key, value)| new_key = key.is_a?(String) ? key.to_sym : key new_value = value.is_a?(Hash) ? symbolize_keys(value) : value result.merge! new_key => new_value end end def self.stringify_keys(object) #:nodoc: return object unless object.is_a?(Hash) object.inject({}) do |result, (key, value)| new_key = key.is_a?(Symbol) ? key.to_s : key new_value = value.is_a?(Hash) ? stringify_keys(value) : value result.merge! new_key => new_value end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
multi_json-1.0.0.rc2 | lib/multi_json/engines/okjson.rb |
multi_json-1.0.0.rc | lib/multi_json/engines/okjson.rb |