def pretty_generate(obj, opts = nil)
    if State === opts
      state, opts = opts, nil
    else
      state = PRETTY_STATE_PROTOTYPE.dup
    end
    if 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
      state.configure(opts)
    end
    state.generate(obj)
  end
:startdoc:
Generate a JSON document from the Ruby data structure _obj_ and return it.
The returned document is a prettier form of the document returned by
#unparse.

The _opts_ argument can be used to configure the generator. See the
generate method for a more detailed explanation.