Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix invalid MultiJson API detection (closes #82)
`#load` is defined in Kernel and inherited in every object, thus Object.respond_to?(:load) will always return true.

MultiJson switched to load/dump from decode/encode. Thus it's safe to use a single check for both encoding and decoding methods.
  • Loading branch information
weppos committed May 7, 2012
1 parent 121e97d commit 5b87c9b
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/execjs/external_runtime.rb
Expand Up @@ -85,21 +85,19 @@ def encode_unicode_codepoints(str)
end
end

if MultiJson.respond_to?(:load)
if MultiJson.respond_to?(:dump)
def json_decode(obj)
MultiJson.load(obj)
end
else
def json_decode(obj)
MultiJson.decode(obj)
end
end

if MultiJson.respond_to?(:dump)
def json_encode(obj)
MultiJson.dump(obj)
end
else
def json_decode(obj)
MultiJson.decode(obj)
end

def json_encode(obj)
MultiJson.encode(obj)
end
Expand Down

0 comments on commit 5b87c9b

Please sign in to comment.