class JSON::Ext::Generator::State
def [](name)
call-seq: [](name)
def [](name) if respond_to?(name) __send__(name) else instance_variable_get("@#{name}") if instance_variables.include?("@#{name}".to_sym) # avoid warning end end
def []=(name, value)
call-seq: []=(name, value)
def []=(name, value) if respond_to?(name_writer = "#{name}=") __send__ name_writer, value else instance_variable_set "@#{name}", value end end
def configure(opts)
Configure this State instance with the Hash _opts_, and return
call-seq: configure(opts)
def configure(opts) unless opts.is_a?(Hash) if opts.respond_to?(:to_hash) opts = opts.to_hash elsif opts.respond_to?(:to_h) opts = opts.to_h else raise TypeError, "can't convert #{opts.class} into Hash" end end _configure(opts) end
def initialize(opts = nil)
* *buffer_initial_length*: sets the initial length of the generator's
option defaults to false.
* *ascii_only*: true if only ASCII characters should be generated. This
encountered. This options defaults to false.
generated, otherwise an exception is thrown, if these values are
* *allow_nan*: true if NaN, Infinity, and -Infinity should be
* *array_nl*: a string that is put at the end of a JSON array (default: ''),
* *object_nl*: a string that is put at the end of a JSON object (default: ''),
* *space_before*: a string that is put before a : pair delimiter (default: ''),
* *space*: a string that is put after, a : or , delimiter (default: ''),
* *indent*: a string used to indent levels (default: ''),
_opts_ can have the following keys:
Instantiates a new State object, configured by _opts_.
call-seq: new(opts = {})
def initialize(opts = nil) if opts && !opts.empty? configure(opts) end end
def to_h
Returns the configuration instance variables as a hash, that can be
call-seq: to_h
def to_h result = { indent: indent, space: space, space_before: space_before, object_nl: object_nl, array_nl: array_nl, allow_nan: allow_nan?, ascii_only: ascii_only?, max_nesting: max_nesting, script_safe: script_safe?, strict: strict?, depth: depth, buffer_initial_length: buffer_initial_length, } instance_variables.each do |iv| iv = iv.to_s[1..-1] result[iv.to_sym] = self[iv] end result end