Skip to content

Commit

Permalink
Use String#+
Browse files Browse the repository at this point in the history
It is available since ruby 2.3.
  • Loading branch information
nobu committed Oct 24, 2024
1 parent c40a330 commit 7efa2c3
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/json/pure/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,14 @@ def json_shift(state)

def json_transform(state)
delim = ",#{state.object_nl}"
result = "{#{state.object_nl}"
result = result.dup if result.frozen? # RUBY_VERSION < 3.0
result = +"{#{state.object_nl}"
depth = state.depth += 1
first = true
indent = !state.object_nl.empty?
each { |key, value|
result << delim unless first
result << state.indent * depth if indent
result = "#{result}#{key.to_s.to_json(state)}#{state.space_before}:#{state.space}"
result = result.dup if result.frozen? # RUBY_VERSION < 3.0
result = +"#{result}#{key.to_s.to_json(state)}#{state.space_before}:#{state.space}"
if state.strict? && !(false == value || true == value || nil == value || String === value || Array === value || Hash === value || Integer === value || Float === value)
raise GeneratorError, "#{value.class} not allowed in JSON"
elsif value.respond_to?(:to_json)
Expand Down

0 comments on commit 7efa2c3

Please sign in to comment.