class String
This monkey patch add ability of turning stirng's encoding into utf8
Example:
require 'string/utf8' p "\xD6\xD0\xCE\xC4".utf8! => "中文"
Constants
- ENCODINGS
Public Instance Methods
utf8!()
click to toggle source
for ruby1.9+
# File lib/string/utf8.rb, line 32 def utf8! ENCODINGS.any? do |c| begin self.encode!('utf-8', c).force_encoding('utf-8') if self.valid_encoding? $enc = c true end rescue end end self end