This method is only available on newer versions.
The first available version (v2_6_3) is shown here.
detect_encoding(string)
public
Detects the encoding of string based on the magic comment
# File lib/rdoc/encoding.rb, line 102
def self.detect_encoding string
result = HEADER_REGEXP.match string
name = result && result[:name]
name ? Encoding.find(name) : nil
end