From 5b87c9b7ece87d9d17faa18c95f70a3c40e69406 Mon Sep 17 00:00:00 2001 From: Simone Carletti Date: Mon, 7 May 2012 15:11:58 +0200 Subject: [PATCH] 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. --- lib/execjs/external_runtime.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/execjs/external_runtime.rb b/lib/execjs/external_runtime.rb index 88a18b8..ec06d3f 100644 --- a/lib/execjs/external_runtime.rb +++ b/lib/execjs/external_runtime.rb @@ -85,21 +85,19 @@ module ExecJS 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