summaryrefslogtreecommitdiff
path: root/ext/json/lib
diff options
context:
space:
mode:
Diffstat (limited to 'ext/json/lib')
-rw-r--r--ext/json/lib/json/common.rb12
1 files changed, 9 insertions, 3 deletions
diff --git a/ext/json/lib/json/common.rb b/ext/json/lib/json/common.rb
index d5444b92c82..13debd1366c 100644
--- a/ext/json/lib/json/common.rb
+++ b/ext/json/lib/json/common.rb
@@ -1,5 +1,4 @@
require 'json/version'
-require 'iconv'
module JSON
class << self
@@ -342,8 +341,15 @@ module JSON
end
# Shortuct for iconv.
- def self.iconv(to, from, string)
- Iconv.iconv(to, from, string).first
+ if String.method_defined?(:encode)
+ def self.iconv(to, from, string)
+ string.encode(to, from)
+ end
+ else
+ require 'iconv'
+ def self.iconv(to, from, string)
+ Iconv.iconv(to, from, string).first
+ end
end
end