From 6604e1b7cd75bef7ed72db699d8f88a7fb56c330 Mon Sep 17 00:00:00 2001 From: hsbt Date: Sat, 23 Feb 2019 03:43:58 +0000 Subject: 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 --- ext/json/lib/json/add/ostruct.rb | 2 +- ext/json/lib/json/add/set.rb | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 ext/json/lib/json/add/set.rb (limited to 'ext/json/lib/json/add') 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 v as a + # Stores class name (OpenStruct) with this struct's values t 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 + -- cgit v1.2.3