Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

JSON::Ext::Generator::State.new

new(opts = {})

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 option defaults to false.

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

See also .from_state #[] #[]= also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0