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.

Instantiates a new State object, configured by opts.

opts can have the following keys:

  • indent: a string used to indent levels (default: ”),

  • space: a string that is put after, a : or , delimiter (default: ”),

  • space_before: a string that is put before a : pair delimiter (default: ”),

  • object_nl: a string that is put at the end of a JSON object (default: ”),

  • array_nl: a string that is put at the end of a JSON array (default: ”),

  • allow_nan: true if NaN, Infinity, and -Infinity should be generated, otherwise an exception is thrown, if these values are encountered. This options defaults to false.

  • ascii_only: true if only ASCII characters should be generated. This ontions defaults to false.

  • buffer_initial_length: sets the initial length of the generator’s internal buffer.

Instance Methods

Returns the value returned by method name.

Sets the attribute name to value.

Returns true, if NaN, Infinity, and -Infinity should be generated, otherwise returns false.

This string is put at the end of a line that holds a JSON array.

This string is put at the end of a line that holds a JSON array.

Returns true, if only ASCII characters should be generated. Otherwise returns false.

This integer returns the current initial length of the buffer.

This sets the initial length of the buffer to length, if length > 0, otherwise its value isn’t changed.

Returns true, if circular data structures should be checked, otherwise returns false.

Configure this State instance with the Hash opts, and return itself.

This integer returns the current depth of data structure nesting.

This sets the maximum level of data structure nesting in the generated JSON to the integer depth, max_nesting = 0 if no maximum should be checked.

Generates a valid JSON document from object obj and returns the result. If no valid JSON document can be created this method raises a GeneratorError exception.

Returns the string that is used to indent levels in the JSON text.

Sets the string that is used to indent levels in the JSON text.

Initializes this object from orig if it can be duplicated/cloned and returns it.

This integer returns the maximum level of data structure nesting in the generated JSON, max_nesting = 0 if no maximum is checked.

This sets the maximum level of data structure nesting in the generated JSON to the integer depth, max_nesting = 0 if no maximum should be checked.

An alias for configure

This string is put at the end of a line that holds a JSON object (or Hash).

This string is put at the end of a line that holds a JSON object (or Hash).

Returns the string that is used to insert a space between the tokens in a JSON string.

Sets space to the string that is used to insert a space between the tokens in a JSON string.

Returns the string that is used to insert a space before the ‘:’ in JSON objects.

Sets the string that is used to insert a space before the ‘:’ in JSON objects.

Returns the configuration instance variables as a hash, that can be passed to the configure method.

An alias for to_h