Class JSON::State
In: lib/json.rb
Parent: Object
StringScanner Parser JSONTreeView MainWindow Gtk::TreeView OptionsMenu EditMenu PopUpMenu FileMenu Gtk::Window Enumerable TreeIter Gtk State lib/json.rb lib/json/editor.rb MenuExtension lib/json/editor.rb Gtk Editor JSON Module: JSON

This class is used to create State instances, that are use to hold data while unparsing a Ruby data structure into a JSON string.

Methods

forget   from_state   new   remember   seen?  

Attributes

array_nl  [RW]  This string is put at the end of a line that holds a JSON array.
indent  [RW]  This string is used to indent levels in the JSON string.
object_nl  [RW]  This string is put at the end of a line that holds a JSON object (or Hash).
space  [RW]  This string is used to include a space between the tokens in a JSON string.

Public Class methods

Creates a State object from opts, which ought to be Hash to create a new State instance configured by opts, something else to create an unconfigured instance. If opts is a State object, it is just returned.

[Source]

     # File lib/json.rb, line 331
331:     def self.from_state(opts)
332:       case opts
333:       when self
334:         opts
335:       when Hash
336:         new(opts)
337:       else
338:         new
339:       end
340:     end

Instantiates a new State object, configured by opts.

[Source]

     # File lib/json.rb, line 343
343:     def initialize(opts = {})
344:       @indent     = opts[:indent]     || ''
345:       @space      = opts[:space]      || ''
346:       @object_nl  = opts[:object_nl]  || ''
347:       @array_nl   = opts[:array_nl]   || ''
348:       @seen       = {}
349:     end

Public Instance methods

Forget object for this Unparsing run.

[Source]

     # File lib/json.rb, line 377
377:     def forget(object)
378:       @seen.delete object.__id__
379:     end

Remember object, to find out if it was already encountered (to find out if a cyclic data structure is unparsed).

[Source]

     # File lib/json.rb, line 372
372:     def remember(object)
373:       @seen[object.__id__] = true
374:     end

Returns true, if object was already seen during this Unparsing run.

[Source]

     # File lib/json.rb, line 366
366:     def seen?(object)
367:       @seen.key?(object.__id__)
368:     end

[Validate]