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 288
288:           def to_json(state = nil, *)
289:             state = State.from_state(state)
290:             state.check_max_nesting
291:             json_transform(state)
292:           end

Private Instance Methods

json_shift(state) click to toggle source
     # File lib/json/pure/generator.rb, line 296
296:           def json_shift(state)
297:             state.object_nl.empty? or return ''
298:             state.indent * state.depth
299:           end
json_transform(state) click to toggle source
     # File lib/json/pure/generator.rb, line 301
301:           def json_transform(state)
302:             delim = ','
303:             delim << state.object_nl
304:             result = '{'
305:             result << state.object_nl
306:             depth = state.depth += 1
307:             first = true
308:             indent = !state.object_nl.empty?
309:             each { |key,value|
310:               result << delim unless first
311:               result << state.indent * depth if indent
312:               result << key.to_s.to_json(state)
313:               result << state.space_before
314:               result << ':'
315:               result << state.space
316:               result << value.to_json(state)
317:               first = false
318:             }
319:             depth = state.depth -= 1
320:             result << state.object_nl
321:             result << state.indent * depth if indent if indent
322:             result << '}'
323:             result
324:           end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.