Method: JSON.fast_generate
- Defined in:
- lib/json/common.rb
.fast_generate(obj, opts = nil) ⇒ Object Also known as: fast_unparse
Generate a JSON document from the Ruby data structure obj and return it. This method disables the checks for circles in Ruby objects.
WARNING: Be careful not to pass any Ruby data structures with circles as obj argument because this will cause JSON to go into an infinite loop.
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/json/common.rb', line 239 def fast_generate(obj, opts = nil) if State === opts state, opts = opts, nil else state = FAST_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 |