Ruby 1.9.2 commandline options

C

Clifford Heath

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 Heath.
 
A

Ammar Ali

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
 
C

Clifford Heath

Ammar said:
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?

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 Heath.
 
A

Ammar Ali

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
 
R

Run Paint Run Run

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.

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.
 
C

Clifford Heath

Run said:
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 Heath.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top