Class Array
In: lib/json.rb
Parent: Object
StringScanner Parser JSONTreeView MainWindow Gtk::TreeView OptionsMenu EditMenu PopUpMenu FileMenu Gtk::Window Enumerable TreeIter Gtk State Integer FalseClass Array Hash Class Float NilClass TrueClass String lib/json.rb lib/json/editor.rb MenuExtension lib/json/editor.rb Gtk Editor JSON Kernel TopLevel

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. depth is used to find out nesting depth, to indent accordingly.

[Source]

     # File lib/json.rb, line 527
527:   def to_json(state = nil, depth = 0)
528:     state = JSON::State.from_state(state)
529:     json_check_circular(state) { json_transform(state, depth) }
530:   end

Private Instance methods

[Source]

     # File lib/json.rb, line 534
534:   def json_check_circular(state)
535:     if state
536:       state.seen?(self) and raise JSON::CircularDatastructure,
537:         "circular data structures not supported!"
538:       state.remember self
539:     end
540:     yield
541:   ensure
542:     state and state.forget self
543:   end

[Source]

     # File lib/json.rb, line 545
545:   def json_shift(state, depth)
546:     state and not state.array_nl.empty? or return ''
547:     state.indent * depth
548:   end

[Source]

     # File lib/json.rb, line 550
550:   def json_transform(state, depth)
551:     delim = ','
552:     delim << state.array_nl if state
553:     result = '['
554:     result << state.array_nl if state
555:     result << map { |value|
556:       json_shift(state, depth + 1) << value.to_json(state, depth + 1)
557:     }.join(delim)
558:     result << state.array_nl if state
559:     result << json_shift(state, depth) 
560:     result << ']'
561:     result
562:   end

[Validate]