Ruby 1.9.2 commandline options

ruby --help lists -E, which doesn’t seem to work as advertised,
but not -K, which does what I wanted. Can someone please check
that the source code and the help message coincide?

Clifford H…

On Wed, Nov 17, 2010 at 12:20 AM, Clifford H. [email protected]
wrote:

ruby --help lists -E, which doesn’t seem to work as advertised,
but not -K, which does what I wanted. Can someone please check
that the source code and the help message coincide?

I’m not sure what you mean by work as advertised, but I would like to
note that the syntax for -E is different that of -K; it takes the full
encoding name, case-insensitive:

ruby -Eutf-8:utf-8
ruby -Eascii:utf-8

Does that do what you except?

Regards,
Ammar

Ammar A. wrote:

ruby -Eascii:utf-8

Does that do what you except?

No, it still complains “invalid multibyte char (US-ASCII)” on
a valid UTF-8 character, in a UTF-8 file having no Unicode BOM.

Also, the help implies that you can set just the external encoding
without the internal encoding, which I did, since I could care less
which internal encoding Ruby uses. ruby --help says:

-Eex[:in] specify the default external and internal character
encodings

The square brackets imply that the internal encoding is optional.

Why is -K not listed in --help? Especially since it’s the option
that seems to actually work…

Clifford H…

On Wed, Nov 17, 2010 at 12:10 PM, Clifford H. [email protected]
wrote:

note that the syntax for -E is different that of -K; it takes the full
Also, the help implies that you can set just the external encoding
without the internal encoding, which I did, since I could care less
which internal encoding Ruby uses.

I believe you’re misunderstanding what internal and external encodings
represent. For a thorough explanation, see http://goo.gl/iUBCX .
Briefly, if your source file contains non-ASCII characters the
recommended approach is to declare a source encoding via a magic
comment. In this case, your file should begin with “# coding: utf-8”.
If you insist on using -K, try ruby -KU instead.

Run Paint Run R. wrote:

On Wed, Nov 17, 2010 at 12:10 PM, Clifford H. [email protected] wrote:
I believe you’re misunderstanding what internal and external encodings
represent. For a thorough explanation, see http://goo.gl/iUBCX .

Thanks, but I’m well aware of the magic comments.
You’re missing the point(s):

$ rvm use 1.9.2
$ ruby -e ‘p ENCODING
#Encoding:UTF-8

so the default encoding is UTF-8. Why does a UTF-8 file fail to be
parsed as UTF-8 then?
(Answer: because Ruby has a schizophrenia about its default encoding,
and defaults to US-ASCII
for files).

Next,

$ ruby -h

lists 23 lines of options, but not -K, which is the one that fixes the
above problem. Why?
(Answer: because someone made arbitrary decisions about which options
need -h help,
or made changes in options without bothering to cross-check the help.
Arbitrary, or careless,
you choose. Either way it should be fixed.)

Clifford H…

On Wed, Nov 17, 2010 at 2:10 PM, Clifford H. [email protected]
wrote:

No, it still complains “invalid multibyte char (US-ASCII)” on
a valid UTF-8 character, in a UTF-8 file having no Unicode BOM.

AFAIK, BOM is not required for UTF-8 so it should work. Can you
isolate and post the offending line?

The square brackets imply that the internal encoding is optional.

Yes, it is optional. I only specified both encodings as an example.

Why is -K not listed in --help? Especially since it’s the option
that seems to actually work…

man ruby does list -K. Another option that is not listed in -h is -U,
which sets internal encoding to utf-8.

Regards,
Ammar