diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-02-23 03:43:58 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-02-23 03:43:58 +0000 |
commit | 6604e1b7cd75bef7ed72db699d8f88a7fb56c330 (patch) | |
tree | b92ad3bacaa1f7f54152af362decaadc30466617 /ext/json/lib/json/add | |
parent | f22ffd83e92a214a697e93fe715d29cbfa52084d (diff) |
Merge json-2.2.0 from flori/json.
https://github.com/flori/json/releases/tag/v2.2.0
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/json/lib/json/add')
-rw-r--r-- | ext/json/lib/json/add/ostruct.rb | 2 | ||||
-rw-r--r-- | ext/json/lib/json/add/set.rb | 29 |
2 files changed, 30 insertions, 1 deletions
diff --git a/ext/json/lib/json/add/ostruct.rb b/ext/json/lib/json/add/ostruct.rb index e064c85ff4..686cf0025d 100644 --- a/ext/json/lib/json/add/ostruct.rb +++ b/ext/json/lib/json/add/ostruct.rb @@ -23,7 +23,7 @@ class OpenStruct } end - # Stores class name (OpenStruct) with this struct's values <tt>v</tt> as a + # Stores class name (OpenStruct) with this struct's values <tt>t</tt> as a # JSON string. def to_json(*args) as_json.to_json(*args) diff --git a/ext/json/lib/json/add/set.rb b/ext/json/lib/json/add/set.rb new file mode 100644 index 0000000000..71e2a0ac8b --- /dev/null +++ b/ext/json/lib/json/add/set.rb @@ -0,0 +1,29 @@ +unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED + require 'json' +end +defined?(::Set) or require 'set' + +class Set + # Import a JSON Marshalled object. + # + # method used for JSON marshalling support. + def self.json_create(object) + new object['a'] + end + + # Marshal the object to JSON. + # + # method used for JSON marshalling support. + def as_json(*) + { + JSON.create_id => self.class.name, + 'a' => to_a, + } + end + + # return the JSON value + def to_json(*args) + as_json.to_json(*args) + end +end + |