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 386
386:     def self.from_state(opts)
387:       case opts
388:       when self
389:         opts
390:       when Hash
391:         new(opts)
392:       else
393:         new
394:       end
395:     end

Instantiates a new State object, configured by opts.

[Source]

     # File lib/json.rb, line 398
398:     def initialize(opts = {})
399:       @indent     = opts[:indent]     || ''
400:       @space      = opts[:space]      || ''
401:       @object_nl  = opts[:object_nl]  || ''
402:       @array_nl   = opts[:array_nl]   || ''
403:       @seen       = {}
404:     end

Public Instance methods

Forget object for this Unparsing run.

[Source]

     # File lib/json.rb, line 432
432:     def forget(object)
433:       @seen.delete object.__id__
434:     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 427
427:     def remember(object)
428:       @seen[object.__id__] = true
429:     end

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

[Source]

     # File lib/json.rb, line 421
421:     def seen?(object)
422:       @seen.key?(object.__id__)
423:     end

[Validate]