Class: Symbol

Inherits:
Object
  • Object
show all
Defined in:
lib/json/add/symbol.rb

Overview

Symbol serialization/deserialization

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.json_create(o) ⇒ Object

Deserializes JSON string by converting the string value stored in the object to a Symbol



22
23
24
# File 'lib/json/add/symbol.rb', line 22

def self.json_create(o)
  o['s'].to_sym
end

Instance Method Details

#as_jsonObject

Returns a hash, that will be turned into a JSON object and represent this object.



9
10
11
12
13
14
# File 'lib/json/add/symbol.rb', line 9

def as_json(*)
  {
    JSON.create_id => self.class.name,
    's'            => to_s,
  }
end

#to_json(*a) ⇒ Object

Stores class name (Symbol) with String representation of Symbol as a JSON string.



17
18
19
# File 'lib/json/add/symbol.rb', line 17

def to_json(*a)
  as_json.to_json(*a)
end