Skip to content

Commit 826cb2a

Browse files
committed
Get rid of JSON.deep_const_get (private API)
1 parent fce1c7e commit 826cb2a

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

lib/json/common.rb

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,13 @@ def create_additions_proc(opts)
7171
end
7272
when object_class
7373
if opts[:create_additions] != false
74-
if class_name = object[JSON.create_id]
75-
klass = JSON.deep_const_get(class_name)
74+
if class_path = object[JSON.create_id]
75+
klass = begin
76+
Object.const_get(class_path)
77+
rescue NameError => e
78+
raise ArgumentError, "can't get const #{class_path}: #{e}"
79+
end
80+
7681
if klass.respond_to?(:json_creatable?) ? klass.json_creatable? : klass.respond_to?(:json_create)
7782
create_additions_warning if create_additions.nil?
7883
object = klass.json_create(object)
@@ -147,16 +152,6 @@ def parser=(parser) # :nodoc:
147152
const_set :Parser, parser
148153
end
149154

150-
# Return the constant located at _path_. The format of _path_ has to be
151-
# either ::A::B::C or A::B::C. In any case, A has to be located at the top
152-
# level (absolute namespace path?). If there doesn't exist a constant at
153-
# the given path, an ArgumentError is raised.
154-
def deep_const_get(path) # :nodoc:
155-
Object.const_get(path)
156-
rescue NameError => e
157-
raise ArgumentError, "can't get const #{path}: #{e}"
158-
end
159-
160155
# Set the module _generator_ to be used by JSON.
161156
def generator=(generator) # :nodoc:
162157
old, $VERBOSE = $VERBOSE, nil

test/json/json_common_interface_test.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ def test_create_id
6868
JSON.create_id = 'json_class'
6969
end
7070

71-
def test_deep_const_get
72-
assert_raise(ArgumentError) { JSON.deep_const_get('Nix::Da') }
73-
assert_equal File::SEPARATOR, JSON.deep_const_get('File::SEPARATOR')
74-
end
75-
7671
def test_parse
7772
assert_equal [ 1, 2, 3, ], JSON.parse('[ 1, 2, 3 ]')
7873
end

0 commit comments

Comments
 (0)