(#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.
Merge pull request #1978 from zaphod42/issue/stable/22804-improper-encoding-support-detection

(#22804) Check for encoding support more robustly