Ruby 1.9.x has by default US-ASCII (7 bit encoding) as file encoding instead of ASCII-8BIT. While this generally does not cause problems, something else does. If a source file has a UTF-8 encoding, all string literals automatically become UTF-8 encoded strings and that causes problems. e.g. You can't really use Win32API properly anymore because the default strings that you create will have to be converted which is not available in Ruby 1.8.x which then again means that your code is not backwards compatible.
There are three ways to avoid this problem. I have tried all three. Two of them would be easily integrated into ARC if they actually worked. :/ The last one is a bit hackish, but it's the only one that I was able to get working.
1. Use -E switch when initializing Ruby to force the "internal" default encoding. There's also an "external" encoding, but that one is for strings that are read from external sources using IO. Regardless, it's not working.
2. Set Encoding#default_internal (and Encoding#default_external) to the wanted encoding. Doesn't work either.
3. Adding a so-called magic comment like "
# encoding: ascii-8bit" in the first line of the script. This one works, but it's really hackish. When I read "magic comment", I immediately thought of "magic numbers". Every half-assed programmer knows that magic numbers are bad practice. :/
Why is this important and how does it affect the source code? Well, apparently not all. A file can be UTF-8 encoded, but if we force the ASCII-8BIT encoding on created strings, they will all be binary strings and hence the scripts will be backwards compatible with Ruby 1.8.x. The only way I see to get this hack working is to simply remove the first line of the script in the script editor and add it back with the BOM (the 3 bytes at the beginning of the file designating a UTF-8 encoded file) and the comment "# encoding: ascii-8bit". Does anybody have any other ideas?
We don't have to worry about using ASCII-8BIT, because it's basically binary encoding. It will work with everything without problems.
Here are a few links if you want to read up on encodings in Ruby 1.9.x, how it affects everything and ways to work with it.
http://www.ruby-doc.org/core-1.9.3/String.html#method-i-encodehttp://www.ruby-doc.org/core-1.9.3/Encoding.htmlhttp://nuclearsquid.com/writings/ruby-1-9-encodingshttp://blog.grayproductions.net/articles/ruby_19s_three_default_encodingshttp://www.ruby-forum.com/topic/141711EDIT: I'd like to avoid aliasing String#new. We're running Ruby 1.9.x, we should keep its features working.
EDIT: I also tried the -K switch already, but we should avoid using that one as it's deprecated. And it didn't seem to work either.
EDIT: And please no recompilation of Ruby. #_# Even though that one might actually be the best solution here, but it could be quite nasty to find the proper pieces of code that need to be changed.