Files

JSON::Pure::Generator::GeneratorMethods::Hash

Public Instance Methods

to_json(state = nil, *) click to toggle source

Returns a JSON string containing a JSON object, that is unparsed from this Hash instance. state is a JSON::State object, that can also be used to configure the produced JSON string output further. depth is used to find out nesting depth, to indent accordingly.

     # File lib/json/pure/generator.rb, line 255
255:           def to_json(state = nil, *)
256:             state = State.from_state(state)
257:             state.check_max_nesting
258:             json_transform(state)
259:           end

Private Instance Methods

json_shift(state) click to toggle source
     # File lib/json/pure/generator.rb, line 263
263:           def json_shift(state)
264:             state.object_nl.empty? or return ''
265:             state.indent * state.depth
266:           end
json_transform(state) click to toggle source
     # File lib/json/pure/generator.rb, line 268
268:           def json_transform(state)
269:             delim = ','
270:             delim << state.object_nl
271:             result = '{'
272:             result << state.object_nl
273:             depth = state.depth += 1
274:             first = true
275:             indent = !state.object_nl.empty?
276:             each { |key,value|
277:               result << delim unless first
278:               result << state.indent * depth if indent
279:               result << key.to_s.to_json(state)
280:               result << state.space_before
281:               result << ':'
282:               result << state.space
283:               result << value.to_json(state)
284:               first = false
285:             }
286:             depth = state.depth -= 1
287:             result << state.object_nl
288:             result << state.indent * depth if indent if indent
289:             result << '}'
290:             result
291:           end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.