summaryrefslogtreecommitdiff
path: root/lib/json/common.rb
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2010-08-06 23:21:55 +0200
committerFlorian Frank <flori@ping.de>2010-08-07 00:39:20 +0200
commit2e7afd48cdd2e2d2455d39e972d2c95d526f3f92 (patch)
tree1ae1f2d978a8cfaa79d92fbaaea6ef7c31cfb846 /lib/json/common.rb
parent391fd98b04ccc7079eec244aa4d701b71bab3da5 (diff)
downloadjson-2e7afd48cdd2e2d2455d39e972d2c95d526f3f92.tar.gz
mange depth in state
Diffstat (limited to 'lib/json/common.rb')
-rw-r--r--lib/json/common.rb12
1 files changed, 3 insertions, 9 deletions
diff --git a/lib/json/common.rb b/lib/json/common.rb
index 3f5b322..c6a31c1 100644
--- a/lib/json/common.rb
+++ b/lib/json/common.rb
@@ -196,6 +196,7 @@ 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 opts
if opts.respond_to? :to_hash
opts = opts.to_hash
@@ -204,10 +205,7 @@ module JSON
else
raise TypeError, "can't convert #{opts.class} into Hash"
end
- state = SAFE_STATE_PROTOTYPE.dup
state = state.configure(opts)
- else
- state = SAFE_STATE_PROTOTYPE
end
state.generate(obj)
end
@@ -225,6 +223,7 @@ 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 opts
if opts.respond_to? :to_hash
opts = opts.to_hash
@@ -233,10 +232,7 @@ module JSON
else
raise TypeError, "can't convert #{opts.class} into Hash"
end
- state = FAST_STATE_PROTOTYPE.dup
state.configure(opts)
- else
- state = FAST_STATE_PROTOTYPE
end
state.generate(obj)
end
@@ -254,6 +250,7 @@ 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 opts
if opts.respond_to? :to_hash
opts = opts.to_hash
@@ -262,10 +259,7 @@ module JSON
else
raise TypeError, "can't convert #{opts.class} into Hash"
end
- state = PRETTY_STATE_PROTOTYPE.dup
state.configure(opts)
- else
- state = PRETTY_STATE_PROTOTYPE
end
state.generate(obj)
end