diff options
Diffstat (limited to 'lib/json/common.rb')
-rw-r--r-- | lib/json/common.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/json/common.rb b/lib/json/common.rb index 13c09ca..244634b 100644 --- a/lib/json/common.rb +++ b/lib/json/common.rb @@ -196,7 +196,6 @@ 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 @@ -205,7 +204,10 @@ 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 @@ -223,7 +225,6 @@ 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 @@ -232,7 +233,10 @@ 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 @@ -250,7 +254,6 @@ 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 @@ -259,7 +262,10 @@ 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 |