summaryrefslogtreecommitdiff
path: root/ext/json/lib/json/add/core.rb
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-26 00:06:35 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-26 00:06:35 +0000
commit54592ad6276a17d95f2186c8631197ddb172020b (patch)
treefd071c795bc3e589237d89dd593f93d7b0376a4f /ext/json/lib/json/add/core.rb
parent9372cdb80a376f352fc55ea895f1ad688cf4a0df (diff)
* ext/json: Update to JSON 1.4.1.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/json/lib/json/add/core.rb')
-rw-r--r--ext/json/lib/json/add/core.rb27
1 files changed, 20 insertions, 7 deletions
diff --git a/ext/json/lib/json/add/core.rb b/ext/json/lib/json/add/core.rb
index 4423e7ad75a..03a00dded42 100644
--- a/ext/json/lib/json/add/core.rb
+++ b/ext/json/lib/json/add/core.rb
@@ -7,6 +7,19 @@ unless Object.const_defined?(:JSON) and ::JSON.const_defined?(:JSON_LOADED) and
end
require 'date'
+class Symbol
+ def to_json(*a)
+ {
+ JSON.create_id => self.class.name,
+ 's' => to_s,
+ }.to_json(*a)
+ end
+
+ def self.json_create(o)
+ o['s'].to_sym
+ end
+end
+
class Time
def self.json_create(object)
if usec = object.delete('u') # used to be tv_usec -> tv_nsec
@@ -21,7 +34,7 @@ class Time
def to_json(*args)
{
- 'json_class' => self.class.name,
+ JSON.create_id => self.class.name,
's' => tv_sec,
'n' => respond_to?(:tv_nsec) ? tv_nsec : tv_usec * 1000
}.to_json(*args)
@@ -37,7 +50,7 @@ class Date
def to_json(*args)
{
- 'json_class' => self.class.name,
+ JSON.create_id => self.class.name,
'y' => year,
'm' => month,
'd' => day,
@@ -63,7 +76,7 @@ class DateTime
def to_json(*args)
{
- 'json_class' => self.class.name,
+ JSON.create_id => self.class.name,
'y' => year,
'm' => month,
'd' => day,
@@ -83,7 +96,7 @@ class Range
def to_json(*args)
{
- 'json_class' => self.class.name,
+ JSON.create_id => self.class.name,
'a' => [ first, last, exclude_end? ]
}.to_json(*args)
end
@@ -98,7 +111,7 @@ class Struct
klass = self.class.name
klass.to_s.empty? and raise JSON::JSONError, "Only named structs are supported!"
{
- 'json_class' => klass,
+ JSON.create_id => klass,
'v' => values,
}.to_json(*args)
end
@@ -113,7 +126,7 @@ class Exception
def to_json(*args)
{
- 'json_class' => self.class.name,
+ JSON.create_id => self.class.name,
'm' => message,
'b' => backtrace,
}.to_json(*args)
@@ -127,7 +140,7 @@ class Regexp
def to_json(*)
{
- 'json_class' => self.class.name,
+ JSON.create_id => self.class.name,
'o' => options,
's' => source,
}.to_json