From: Michael Selig Date: 2008-10-12T08:11:17+09:00 Subject: [ruby-core:19298] [Feature #639] New String#encode_internal method Feature #639: New String#encode_internal method http://redmine.ruby-lang.org/issues/show/639 Author: Michael Selig Status: Open, Priority: Normal Category: M17N Now that we have default_internal, I think there needs to be an easy way to check that a string is that encoding and if not transcode it. This is especially needed in libraries and other methods which are expected to return strings in defult_internal encoding if it is set. Suggested implementation: class String def encode_internal intern = Encoding.default_internal # Do nothing if default_internal not set return self unless intern # Do nothing if already in default_internal encoding return self if encoding == intern # Just use "force_encoding" if compatible eg: ASCII/UTF-8 return force_encoding(intern) if Encoding.compatible(self, intern) == intern # Otherwise transcode encode(intern) end end ---------------------------------------- http://redmine.ruby-lang.org