Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7efa2c3

Browse files
committed
Use String#+
It is available since ruby 2.3.
1 parent c40a330 commit 7efa2c3

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

lib/json/pure/generator.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,16 +407,14 @@ def json_shift(state)
407407

408408
def json_transform(state)
409409
delim = ",#{state.object_nl}"
410-
result = "{#{state.object_nl}"
411-
result = result.dup if result.frozen? # RUBY_VERSION < 3.0
410+
result = +"{#{state.object_nl}"
412411
depth = state.depth += 1
413412
first = true
414413
indent = !state.object_nl.empty?
415414
each { |key, value|
416415
result << delim unless first
417416
result << state.indent * depth if indent
418-
result = "#{result}#{key.to_s.to_json(state)}#{state.space_before}:#{state.space}"
419-
result = result.dup if result.frozen? # RUBY_VERSION < 3.0
417+
result = +"#{result}#{key.to_s.to_json(state)}#{state.space_before}:#{state.space}"
420418
if state.strict? && !(false == value || true == value || nil == value || String === value || Array === value || Hash === value || Integer === value || Float === value)
421419
raise GeneratorError, "#{value.class} not allowed in JSON"
422420
elsif value.respond_to?(:to_json)

0 commit comments

Comments
 (0)