mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34973 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
25 lines
623 B
Ruby
25 lines
623 B
Ruby
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
|
require 'json'
|
|
end
|
|
|
|
# Symbol serialization/deserialization
|
|
class Symbol
|
|
# Returns a hash, that will be turned into a JSON object and represent this
|
|
# object.
|
|
def as_json(*)
|
|
{
|
|
JSON.create_id => self.class.name,
|
|
's' => to_s,
|
|
}
|
|
end
|
|
|
|
# Stores class name (Symbol) with String representation of Symbol as a JSON string.
|
|
def to_json(*a)
|
|
as_json.to_json(*a)
|
|
end
|
|
|
|
# Deserializes JSON string by converting the <tt>string</tt> value stored in the object to a Symbol
|
|
def self.json_create(o)
|
|
o['s'].to_sym
|
|
end
|
|
end
|