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

* ext/json: Merge json gem v1.5.4 (3dab4c5a6a97fac03dac).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2011-08-31 06:56:16 +00:00
parent 64e0cae274
commit c06658feba
7 changed files with 54 additions and 37 deletions

View file

@ -1,3 +1,7 @@
Wed Aug 31 15:54:11 2011 NARUSE, Yui <naruse@ruby-lang.org>
* ext/json: Merge json gem v1.5.4 (3dab4c5a6a97fac03dac).
Wed Aug 31 13:09:41 2011 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
* numeric.c (flo_round): Avoid overflow by optimizing for trivial

View file

@ -1001,6 +1001,8 @@ static VALUE cState_generate(VALUE self, VALUE obj)
* * *allow_nan*: true if NaN, Infinity, and -Infinity should be
* generated, otherwise an exception is thrown, if these values are
* encountered. This options defaults to false.
* * *quirks_mode*: Enables quirks_mode for parser, that is for example
* generating single JSON values instead of documents is possible.
*/
static VALUE cState_initialize(int argc, VALUE *argv, VALUE self)
{

View file

@ -0,0 +1,22 @@
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
require 'json'
end
defined?(::Complex) or require 'complex'
class Complex
def self.json_create(object)
Complex(object['r'], object['i'])
end
def as_json(*)
{
JSON.create_id => self.class.name,
'r' => real,
'i' => imag,
}
end
def to_json(*)
as_json.to_json
end
end

View file

@ -241,39 +241,3 @@ class Regexp
as_json.to_json
end
end
class Rational
def self.json_create(object)
Rational(object['n'], object['d'])
end
def as_json(*)
{
JSON.create_id => self.class.name,
'n' => numerator,
'd' => denominator,
}
end
def to_json(*)
as_json.to_json
end
end
class Complex
def self.json_create(object)
Complex(object['r'], object['i'])
end
def as_json(*)
{
JSON.create_id => self.class.name,
'r' => real,
'i' => imag,
}
end
def to_json(*)
as_json.to_json
end
end

View file

@ -0,0 +1,22 @@
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
require 'json'
end
defined?(::Rational) or require 'rational'
class Rational
def self.json_create(object)
Rational(object['n'], object['d'])
end
def as_json(*)
{
JSON.create_id => self.class.name,
'n' => numerator,
'd' => denominator,
}
end
def to_json(*)
as_json.to_json
end
end

View file

@ -1618,6 +1618,9 @@ static VALUE convert_encoding(VALUE source)
* defaults to true.
* * *object_class*: Defaults to Hash
* * *array_class*: Defaults to Array
* * *quirks_mode*: Enables quirks_mode for parser, that is for example
* parsing single JSON values instead of documents is possible.
*
*/
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
{

View file

@ -3,7 +3,7 @@
require 'test/unit'
require File.join(File.dirname(__FILE__), 'setup_variant')
load 'json/add/core.rb'
require 'json/add/core.rb'
require 'date'
class TC_JSONAddition < Test::Unit::TestCase