Permalink
Browse files

Merge pull request #106 from f1sherman/fix-generate-nil-opts-error

fix bug where JSON.generate(["foo"], nil) raises NoMethodError: undefine...
  • Loading branch information...
2 parents 57588ea + e955726 commit 5d90659c696531d4a1888b3d1eae485f5d6e9bc3 @brianmario committed Sep 12, 2012
Showing with 9 additions and 10 deletions.
  1. +9 −10 lib/yajl/json_gem/encoding.rb
@@ -17,17 +17,16 @@ module JSON
class JSONError < StandardError; end unless defined?(JSON::JSONError)
class GeneratorError < JSONError; end unless defined?(JSON::GeneratorError)
- def self.generate(obj, opts={})
- begin
- options_map = {}
- if opts.has_key?(:indent)
- options_map[:pretty] = true
- options_map[:indent] = opts[:indent]
- end
- Yajl::Encoder.encode(obj, options_map)
- rescue Yajl::EncodeError => e
- raise JSON::GeneratorError, e.message
+ def self.generate(obj, opts=nil)
+ opts ||= {}
+ options_map = {}
+ if opts.has_key?(:indent)
+ options_map[:pretty] = true
+ options_map[:indent] = opts[:indent]
end
+ Yajl::Encoder.encode(obj, options_map)
+ rescue Yajl::EncodeError => e
+ raise JSON::GeneratorError, e.message
end
def self.pretty_generate(obj, opts={})

0 comments on commit 5d90659

Please sign in to comment.