diff options
author | tompng <tomoyapenguin@gmail.com> | 2023-12-04 19:18:14 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2023-12-05 12:04:08 +0900 |
commit | 70740deea793274f6e38a7b7fc3688aa709fd1d8 (patch) | |
tree | fe7b83ca7bb869d94a01cfa0efc95161072fc49e /ext/json | |
parent | e6b35e8a6d70892037503d74cec2657b2b8bd116 (diff) | |
download | ruby-70740deea793274f6e38a7b7fc3688aa709fd1d8.tar.gz |
[flori/json] Fix JSON.dump overload combination
https://github.com/flori/json/commit/41c2712a3b
Diffstat (limited to 'ext/json')
-rw-r--r-- | ext/json/lib/json/common.rb | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/ext/json/lib/json/common.rb b/ext/json/lib/json/common.rb index 5ba2aade0f..090066012d 100644 --- a/ext/json/lib/json/common.rb +++ b/ext/json/lib/json/common.rb @@ -612,16 +612,13 @@ module JSON # Output: # {"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"} def dump(obj, anIO = nil, limit = nil, kwargs = nil) - if anIO and limit.nil? - anIO = anIO.to_io if anIO.respond_to?(:to_io) - unless anIO.respond_to?(:write) - if kwargs.nil? and anIO.is_a?(Hash) - kwargs = anIO - else - limit = anIO - end - anIO = nil - end + io_limit_opt = [anIO, limit, kwargs].compact + kwargs = io_limit_opt.pop if io_limit_opt.last.is_a?(Hash) + anIO, limit = io_limit_opt + if anIO.respond_to?(:to_io) + anIO = anIO.to_io + elsif limit.nil? && !anIO.respond_to?(:write) + anIO, limit = nil, anIO end opts = JSON.dump_default_options opts = opts.merge(:max_nesting => limit) if limit @@ -642,12 +639,14 @@ module JSON string.encode(to, from) end - private - def merge_dump_options(opts, strict: NOT_SET) opts = opts.merge(strict: strict) if NOT_SET != strict opts end + + class << self + private :merge_dump_options + end end module ::Kernel |