# File lib/json/common.rb, line 214
214:   def pretty_generate(obj, opts = nil)
215:     state = JSON.state.new(
216:       :indent     => '  ',
217:       :space      => ' ',
218:       :object_nl  => "\n",
219:       :array_nl   => "\n",
220:       :check_circular => true
221:     )
222:     if opts
223:       if opts.respond_to? :to_hash
224:         opts = opts.to_hash
225:       elsif opts.respond_to? :to_h
226:         opts = opts.to_h
227:       else
228:         raise TypeError, "can't convert #{opts.class} into Hash"
229:       end
230:       state.configure(opts)
231:     end
232:     obj.to_json(state)
233:   end