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
Attributes
[RW] | array_nl | This string is put at the end of a line that holds a JSON array. |
[RW] | indent | This string is used to indent levels in the JSON string. |
[RW] | object_nl | This string is put at the end of a line that holds a JSON object (or Hash). |
[RW] | space | 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.
[ show source ]
# File lib/facets/more/json.rb, line 349 def self.from_state(opts) case opts when self opts when Hash new(opts) else new end end
Instantiates a new State object, configured by opts.
[ show source ]
# File lib/facets/more/json.rb, line 361 def initialize(opts = {}) @indent = opts[:indent] || '' @space = opts[:space] || '' @object_nl = opts[:object_nl] || '' @array_nl = opts[:array_nl] || '' @seen = {} end
Public Instance methods
Forget object for this Unparsing run.
[ show source ]
# File lib/facets/more/json.rb, line 395 def forget(object) @seen.delete object.__id__ end
Remember object, to find out if it was already encountered (to find out if a cyclic data structure is unparsed).
[ show source ]
# File lib/facets/more/json.rb, line 390 def remember(object) @seen[object.__id__] = true end
Returns true, if object was already seen during this Unparsing run.
[ show source ]
# File lib/facets/more/json.rb, line 384 def seen?(object) @seen.key?(object.__id__) end