class JSON::TruffleRuby::Generator::State
def configure(opts)
Configure this State instance with the Hash _opts_, and return
def configure(opts) 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 opts.each do |key, value| instance_variable_set "@#{key}", value end # NOTE: If adding new instance variables here, check whether #generate should check them for #generate_json @indent = opts[:indent] || '' if opts.key?(:indent) @space = opts[:space] || '' if opts.key?(:space) @space_before = opts[:space_before] || '' if opts.key?(:space_before) @object_nl = opts[:object_nl] || '' if opts.key?(:object_nl) @array_nl = opts[:array_nl] || '' if opts.key?(:array_nl) @allow_nan = !!opts[:allow_nan] if opts.key?(:allow_nan) @ascii_only = opts[:ascii_only] if opts.key?(:ascii_only) @depth = opts[:depth] || 0 @buffer_initial_length ||= opts[:buffer_initial_length] @script_safe = if opts.key?(:script_safe) !!opts[:script_safe] elsif opts.key?(:escape_slash) !!opts[:escape_slash] else false end @strict = !!opts[:strict] if opts.key?(:strict) if !opts.key?(:max_nesting) # defaults to 100 @max_nesting = 100 elsif opts[:max_nesting] @max_nesting = opts[:max_nesting] else @max_nesting = 0 end self end