In article <op.uhlk4avz9245dp / kool>,
  "Michael Selig" <michael.selig / fs.com.au> writes:

> I have noticed this under Linux:
>
> ruby -v -E UTF-16BE -e "open('/tmp/xx')"
> ruby 1.9.0 (2008-09-16 revision 19371) [i686-linux]
> -e:1:in `initialize': ASCII incompatible encoding needs binmode  
> (ArgumentError)
> 	from -e:1:in `open'
> 	from -e:1:in `<main>'
>
> So it seems the only way I can open a UTF-16 file for reading is with the  
> "b" flag, which I thought was only for Windows.

Ruby converts newlines on ASCII.  There is no chance to do
it if UTF-16 without conversion.

However it is really required only if system newline is not
0x0a.

It is possible to accept "r:UTF-16" on Unix.
However I think "b" should be used for portability.

> The weird thing is that I can open it for writing without "b".

For writing, encoding conversion is always required for
ASCII incompatible encoding.  So newline conversion can be
done with that.
-- 
Tanaka Akira