[flori/json] Remove unnecessary code

In `JSON#generate` and `JSON#fast_generate`:

- When the given `opts` is a `JSON::State` the variable is set to
  `nil`.
- But it will be never used as the next `if` blocks will not be
  executed.
- `JSON::State#configure` does the conversion to `Hash`, the
  conversions in the `if` block are just duplication.
- `JSON::State.new` does the same thing with `configure` when an
  argument is given.

https://github.com/flori/json/commit/5d9ab87f8e
This commit is contained in:
Nobuyoshi Nakada 2023-07-17 11:45:00 +09:00
Родитель 104089ce02
Коммит 768668a4de
1 изменённых файлов: 4 добавлений и 24 удалений

Просмотреть файл

@ -295,19 +295,9 @@ module JSON
#
def generate(obj, opts = nil)
if State === opts
state, opts = opts, nil
state = opts
else
state = State.new
end
if opts
if opts.respond_to? :to_hash
opts = opts.to_hash
elsif opts.respond_to? :to_h
opts = opts.to_h
else
raise TypeError, "can't convert #{opts.class} into Hash"
end
state = state.configure(opts)
state = State.new(opts)
end
state.generate(obj)
end
@ -334,19 +324,9 @@ module JSON
# JSON.fast_generate(a)
def fast_generate(obj, opts = nil)
if State === opts
state, opts = opts, nil
state = opts
else
state = JSON.create_fast_state
end
if opts
if opts.respond_to? :to_hash
opts = opts.to_hash
elsif opts.respond_to? :to_h
opts = opts.to_h
else
raise TypeError, "can't convert #{opts.class} into Hash"
end
state.configure(opts)
state = JSON.create_fast_state.configure(opts)
end
state.generate(obj)
end