summaryrefslogtreecommitdiff
path: root/lib/json/common.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/json/common.rb')
-rw-r--r--lib/json/common.rb18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/json/common.rb b/lib/json/common.rb
index bc8c952..43e249c 100644
--- a/lib/json/common.rb
+++ b/lib/json/common.rb
@@ -198,7 +198,11 @@ module JSON
# amount of sanity checks, and the pretty_generate method for some
# defaults for pretty output.
def generate(obj, opts = nil)
- state = SAFE_STATE_PROTOTYPE.dup
+ if State === opts
+ state, opts = opts, nil
+ else
+ state = SAFE_STATE_PROTOTYPE.dup
+ end
if opts
if opts.respond_to? :to_hash
opts = opts.to_hash
@@ -225,7 +229,11 @@ module JSON
# *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.
def fast_generate(obj, opts = nil)
- state = FAST_STATE_PROTOTYPE.dup
+ 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
@@ -252,7 +260,11 @@ module JSON
# The _opts_ argument can be used to configure the generator. See the
# generate method for a more detailed explanation.
def pretty_generate(obj, opts = nil)
- state = PRETTY_STATE_PROTOTYPE.dup
+ 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