(#22804) Check for encoding support more robustly

The REXML module, when included outside of a module or class, will create a
::Encoding module on ruby 1.8.7. That caused the encoding conversion code to
mistakenly think that it was running on a ruby that supported encodings
(which 1.8.7 does not). By being a bit more specific on this check we can
avoid mistaken attempts to control the encoding of the string.