String#encode and Ruby’s Encoding class are built in: every string carries its encoding, File.read takes an encoding: option (including "bom|utf-8"), and encode converts between 100+ encodings. No detection.
charlock_holmes binds ICU: fast, accurate detection plus transcoding, and it tells text from binary data. It’s a C extension that needs ICU installed. GitHub’s Linguist uses it.
rchardet is a pure Ruby port of Python’s chardet: no native dependencies, slower, LGPL.
charlock_holmescharlock_holmes detects the character encoding of text in Ruby using ICU and transcodes it. How to install it, detect a file's encoding.
rchardetrchardet is a pure Ruby character encoding detector ported from Python's chardet. How to install it, detect a file's encoding and convert it to UTF-8.
String#encodeRuby's built-in Encoding support reads and writes text files in any encoding. How to read Windows-1252 and UTF-16 files, strip a BOM, fix invalid UTF-8.