Class: Symbol
Relationships & Source Files | |
Inherits: | Object |
Defined in: | ext/json/lib/json/add/symbol.rb |
Class Method Summary
-
.json_create(o)
See #as_json.
Instance Method Summary
-
#as_json
Methods
as_json
and .json_create may be used to serialize and deserialize a Symbol object; see Marshal. -
#to_json(*a)
Returns a
::JSON
string representingself
:
Class Method Details
.json_create(o)
See #as_json.
# File 'ext/json/lib/json/add/symbol.rb', line 44
def self.json_create(o) o['s'].to_sym end
Instance Method Details
#as_json
Methods as_json
and .json_create may be used to serialize and deserialize a Symbol object; see Marshal.
Method as_json
serializes self
, returning a 2-element hash representing self
:
require 'json/add/symbol'
x = :foo.as_json
# => {"json_class"=>"Symbol", "s"=>"foo"}
Method JSON.create
deserializes such a hash, returning a Symbol object:
Symbol.json_create(x) # => :foo
#to_json(*a)
Returns a ::JSON
string representing self
:
require 'json/add/symbol'
puts :foo.to_json
Output:
# {"json_class":"Symbol","s":"foo"}
# File 'ext/json/lib/json/add/symbol.rb', line 39
def to_json(*a) as_json.to_json(*a) end