diff --git a/lib/json/pure/generator.rb b/lib/json/pure/generator.rb index f417b5431..62d06b412 100644 --- a/lib/json/pure/generator.rb +++ b/lib/json/pure/generator.rb @@ -224,7 +224,7 @@ def configure(opts) else raise TypeError, "can't convert #{opts.class} into Hash" end - for key, value in opts + opts.each do |key, value| instance_variable_set "@#{key}", value end @indent = opts[:indent] if opts.key?(:indent) @@ -260,7 +260,7 @@ def configure(opts) # passed to the configure method. def to_h result = {} - for iv in instance_variables + instance_variables.each do |iv| iv = iv.to_s[1..-1] result[iv.to_sym] = self[iv] end @@ -327,20 +327,15 @@ def json_shift(state) end def json_transform(state) - delim = ',' - delim << state.object_nl - result = '{' - result << state.object_nl + delim = ",#{state.object_nl}" + result = "{#{state.object_nl}" depth = state.depth += 1 first = true indent = !state.object_nl.empty? - each { |key,value| + each { |key, value| result << delim unless first result << state.indent * depth if indent - result << key.to_s.to_json(state) - result << state.space_before - result << ':' - result << state.space + result = "#{result}#{key.to_s.to_json(state)}#{state.space_before}:#{state.space}" if value.respond_to?(:to_json) result << value.to_json(state) else