Module JSON::Pure::Generator::GeneratorMethods::Array
In: lib/json/pure/generator.rb
JSONError GeneratorError ParserError MissingUnicodeSupport NestingError StandardError Gtk StringScanner Parser State lib/json/common.rb Ext Editor lib/json/pure/parser.rb lib/json/pure/generator.rb Object Integer FalseClass Array Hash Float NilClass TrueClass Extend String GeneratorMethods Generator Pure JSON dot/m_9_3.png

Methods

Public Instance methods

Returns a JSON string containing a JSON array, that is unparsed from this Array instance. state is a JSON::State object, that can also be used to configure the produced JSON string output further.

[Source]

     # File lib/json/pure/generator.rb, line 299
299:           def to_json(state = nil, *)
300:             state = State.from_state(state)
301:             state.check_max_nesting
302:             json_transform(state)
303:           end

Private Instance methods

[Source]

     # File lib/json/pure/generator.rb, line 307
307:           def json_transform(state)
308:             delim = ','
309:             delim << state.array_nl
310:             result = '['
311:             result << state.array_nl
312:             depth = state.depth += 1
313:             first = true
314:             indent = !state.array_nl.empty?
315:             each { |value|
316:               result << delim unless first
317:               result << state.indent * depth if indent
318:               result << value.to_json(state)
319:               first = false
320:             }
321:             depth = state.depth -= 1
322:             result << state.array_nl
323:             result << state.indent * depth if indent
324:             result << ']'
325:           end

[Validate]