diff options
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | lib/json/add/core.rb | 3 | ||||
-rw-r--r-- | lib/json/common.rb | 18 | ||||
-rw-r--r-- | lib/json/ext.rb | 2 | ||||
-rw-r--r-- | lib/json/pure.rb | 2 |
5 files changed, 19 insertions, 8 deletions
@@ -2,6 +2,8 @@ * Included Java source codes for the Jruby extension made by Daniel Luz <dev@mernen.com>. * Output full exception message of deep_const_get to aid debugging. + * Fixed an issue with ruby 1.9 Module#const_defined? method, that was + reported by Riley Goodside. 2010-08-09 (1.4.6) * Fixed oversight reported in http://github.com/flori/json/issues/closed#issue/23, always create a new object from the state prototype. diff --git a/lib/json/add/core.rb b/lib/json/add/core.rb index 03a00dd..7a901d0 100644 --- a/lib/json/add/core.rb +++ b/lib/json/add/core.rb @@ -1,8 +1,7 @@ # This file contains implementations of ruby core's custom objects for # serialisation/deserialisation. -unless Object.const_defined?(:JSON) and ::JSON.const_defined?(:JSON_LOADED) and - ::JSON::JSON_LOADED +unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED require 'json' end require 'date' diff --git a/lib/json/common.rb b/lib/json/common.rb index 1ca53cb..f8ce2da 100644 --- a/lib/json/common.rb +++ b/lib/json/common.rb @@ -23,7 +23,7 @@ module JSON # Set the JSON parser class _parser_ to be used by JSON. def parser=(parser) # :nodoc: @parser = parser - remove_const :Parser if const_defined? :Parser + remove_const :Parser if JSON.const_defined_in?(self, :Parser) const_set :Parser, parser end @@ -34,8 +34,8 @@ module JSON def deep_const_get(path) # :nodoc: path.to_s.split(/::/).inject(Object) do |p, c| case - when c.empty? then p - when p.const_defined?(c) then p.const_get(c) + when c.empty? then p + when JSON.const_defined_in?(p, c) then p.const_get(c) else begin p.const_missing(c) @@ -350,7 +350,7 @@ module JSON end # Shortuct for iconv. - if String.method_defined?(:encode) + if ::String.method_defined?(:encode) def self.iconv(to, from, string) string.encode(to, from) end @@ -360,6 +360,16 @@ module JSON Iconv.iconv(to, from, string).first end end + + if ::Object.method(:const_defined?).arity == 1 + def self.const_defined_in?(modul, constant) + modul.const_defined?(constant) + end + else + def self.const_defined_in?(modul, constant) + modul.const_defined?(constant, false) + end + end end module ::Kernel diff --git a/lib/json/ext.rb b/lib/json/ext.rb index a5e3148..7264a85 100644 --- a/lib/json/ext.rb +++ b/lib/json/ext.rb @@ -11,5 +11,5 @@ module JSON JSON.generator = Generator end - JSON_LOADED = true unless const_defined?(:JSON_LOADED) + JSON_LOADED = true unless defined?(::JSON::JSON_LOADED) end diff --git a/lib/json/pure.rb b/lib/json/pure.rb index f7ee3df..dbac93c 100644 --- a/lib/json/pure.rb +++ b/lib/json/pure.rb @@ -11,5 +11,5 @@ module JSON JSON.generator = Generator end - JSON_LOADED = true unless const_defined?(:JSON_LOADED) + JSON_LOADED = true unless defined?(::JSON::JSON_LOADED) end |