summaryrefslogtreecommitdiff
path: root/lib/json/common.rb
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2010-12-31 19:09:14 +0100
committerFlorian Frank <flori@ping.de>2011-01-02 21:13:45 +0100
commit52cab32644a0f77ffa7653232f79724b33f19050 (patch)
treea8e24b842ca917dce9a6c02a5bf54b67a33db676 /lib/json/common.rb
parenta424e80b9666645e0ab9d1f44f6fe6e1e2adb865 (diff)
downloadjson-52cab32644a0f77ffa7653232f79724b33f19050.tar.gz
Fix for ruby 1.9 const_defined? method
ruby 1.9 breaks backwards compatibility by usіng the wrong default value for its newly introduced second argument. This patch implements a work around, to make this gem work on both ruby 1.8 and 1.9.
Diffstat (limited to 'lib/json/common.rb')
-rw-r--r--lib/json/common.rb18
1 files changed, 14 insertions, 4 deletions
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