pretty_generate(obj, opts = nil)
public
Unparse the Ruby data structure obj into a JSON string and return it. The returned string is a
prettier form of the string returned by #unparse.
The opts argument can be used to configure the generator, see the
generate method for a more detailed
explanation.
# File ext/json/lib/json/common.rb, line 214
def pretty_generate(obj, opts = nil)
state = JSON.state.new(
:indent => ' ',
:space => ' ',
:object_nl => "\n",
:array_nl => "\n",
:check_circular => true
)
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
obj.to_json(state)
end