Skip to content
instance method

Set#as_json

(*untyped) -> ::Hash[::String, ::String | ::Array[A]]
as_json(*)

Methods Set#as_json and Set.json_create may be used to serialize and deserialize a Set object; see Marshal.

Method Set#as_json serializes self, returning a 2-element hash representing self:

Example
require 'json/add/set'
x = Set.new(%w/foo bar baz/).as_json
# => {"json_class"=>"Set", "a"=>["foo", "bar", "baz"]}

Method JSON.create deserializes such a hash, returning a Set object:

Example
Set.json_create(x) # => #<Set: {"foo", "bar", "baz"}>
See also #add? #classify #add #clear also in 3.4 · 3.3 · 3.2 · 3.1 · 3.0