summaryrefslogtreecommitdiff
path: root/lib/json/common.rb
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2011-07-27 02:14:54 +0200
committerFlorian Frank <flori@ping.de>2011-07-27 02:40:10 +0200
commitbdb2b910a5ebd92471de13d7e90d54408f6b093e (patch)
treeae717c3fa4721733def0fe5b450fd350380814ce /lib/json/common.rb
parent9320a2a18a4d09f8e8a83129db793057968928b1 (diff)
downloadjson-bdb2b910a5ebd92471de13d7e90d54408f6b093e.tar.gz
started quirks mode for generator
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 1a5f048..1330acc 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 a 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