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

[Source]

     # File lib/json.rb, line 583
583:   def to_json(state = nil, depth = 0)
584:     state = JSON::State.from_state(state)
585:     json_check_circular(state) { json_transform(state, depth) }
586:   end

Private Instance methods

[Source]

     # File lib/json.rb, line 590
590:   def json_check_circular(state)
591:     if state
592:       state.seen?(self) and raise JSON::CircularDatastructure,
593:         "circular data structures not supported!"
594:       state.remember self
595:     end
596:     yield
597:   ensure
598:     state and state.forget self
599:   end

[Source]

     # File lib/json.rb, line 601
601:   def json_shift(state, depth)
602:     state and not state.array_nl.empty? or return ''
603:     state.indent * depth
604:   end

[Source]

     # File lib/json.rb, line 606
606:   def json_transform(state, depth)
607:     delim = ','
608:     delim << state.array_nl if state
609:     result = '['
610:     result << state.array_nl if state
611:     result << map { |value|
612:       json_shift(state, depth + 1) << value.to_json(state, depth + 1)
613:     }.join(delim)
614:     result << state.array_nl if state
615:     result << json_shift(state, depth) 
616:     result << ']'
617:     result
618:   end

[Validate]