[ruby/json] Cleanup Kernel#JSON
https://github.com/ruby/json/commit/573ebdca89
This commit is contained in:
parent
26a9ccbf83
commit
77a52787a6
@ -123,7 +123,7 @@ module JSON
|
|||||||
# Otherwise, calls JSON.generate with +object+ and +opts+ (see method #generate):
|
# Otherwise, calls JSON.generate with +object+ and +opts+ (see method #generate):
|
||||||
# ruby = [0, 1, nil]
|
# ruby = [0, 1, nil]
|
||||||
# JSON[ruby] # => '[0,1,null]'
|
# JSON[ruby] # => '[0,1,null]'
|
||||||
def [](object, opts = {})
|
def [](object, opts = nil)
|
||||||
if object.is_a?(String)
|
if object.is_a?(String)
|
||||||
return JSON.parse(object, opts)
|
return JSON.parse(object, opts)
|
||||||
elsif object.respond_to?(:to_str)
|
elsif object.respond_to?(:to_str)
|
||||||
@ -1038,16 +1038,7 @@ module ::Kernel
|
|||||||
#
|
#
|
||||||
# The _opts_ argument is passed through to generate/parse respectively. See
|
# The _opts_ argument is passed through to generate/parse respectively. See
|
||||||
# generate and parse for their documentation.
|
# generate and parse for their documentation.
|
||||||
def JSON(object, *args)
|
def JSON(object, opts = nil)
|
||||||
if object.is_a?(String)
|
JSON[object, opts]
|
||||||
return JSON.parse(object, args.first)
|
|
||||||
elsif object.respond_to?(:to_str)
|
|
||||||
str = object.to_str
|
|
||||||
if str.is_a?(String)
|
|
||||||
return JSON.parse(object.to_str, args.first)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
JSON.generate(object, args.first)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user