I have just updated my Ruby into 1.9.0, and tried to run one of my programs. But I got that response:
> zrzutnik.rb:19: invalid multibyte char (US-ASCII)
> zrzutnik.rb:19: syntax error, unexpected $end, expecting keyword_end
> print "Klucz #{kl.inspect} jest nieznany. Zdefiniować
> nowy [T/N]? "
> ^
(at Ruby 1.8 it works fine)
Does it mean I can't use any longer any non-latin character in my String-s? WTF?
PS: The file ("zrzutnik.rb") is encoded all in utf-8 (without BOM).
In Ruby 1.9, every String object knows the encoding of itself. So you
need to designate the source code encoding by a magic comment.
The style of a magic comment is:
# coding: [source_code_encoding]
You can write other element in a magic comment:
# -*- coding: utf-8 -*-
If you write the magic comment, you must write it on the first line
(or the second line if the first line is a shebang) of your source
code.
example (the number of left side is a line number)
1: #!/usr/bin/ruby
2: # coding: utf-8
3: str = "The non-ascii string: Zdefiniować nowy"
"felix.leg" <felix.leg@vp.pl> wrote in message news:igv4bb$a49$1@news.onet.pl...
I have just updated my Ruby into 1.9.0, and tried to run one of my programs. But I got that response:
> zrzutnik.rb:19: invalid multibyte char (US-ASCII)
> zrzutnik.rb:19: syntax error, unexpected $end, expecting keyword_end
> print "Klucz #{kl.inspect} jest nieznany. Zdefiniować
> nowy [T/N]? "
> ^
(at Ruby 1.8 it works fine)
Does it mean I can't use any longer any non-latin character in my String-s? WTF?
PS: The file ("zrzutnik.rb") is encoded all in utf-8 (without BOM).
Hello:
In Ruby 1.9.x you need to explicitly specify the encoding of your strings to fit your requirements. Your default string encoding appears to be US-ASCII (mine is CP850). If you want it to be UTF-8 use the following to force the string to that encoding:
I have just updated my Ruby into 1.9.0, and tried to run one of my
programs. But I got that response:
> zrzutnik.rb:19: invalid multibyte char (US-ASCII)
> zrzutnik.rb:19: invalid multibyte char (US-ASCII)
> zrzutnik.rb:19: syntax error, unexpected $end, expecting keyword_end
> print "Klucz #{kl.inspect} jest nieznany. Zdefiniować
> nowy [T/N]? "
> ^
(at Ruby 1.8 it works fine)
Does it mean I can't use any longer any non-latin character in my
String-s? WTF?
PS: The file ("zrzutnik.rb") is encoded all in utf-8 (without BOM).
You want to know the new String rules in ruby 1.9? Try
(and click through to string19.rb)
I've found about 200 rules so far. I'm sticking with 1.8.
"felix.leg" <felix.leg@vp.pl> wrote in message
news:igv4bb$a49$1@news.onet.pl...
I have just updated my Ruby into 1.9.0, and tried to run one of my
programs. But I got that response:
> zrzutnik.rb:19: invalid multibyte char (US-ASCII)
> zrzutnik.rb:19: syntax error, unexpected $end, expecting keyword_end
> print "Klucz #{kl.inspect} jest nieznany. Zdefiniować
> nowy [T/N]? "
> ^
(at Ruby 1.8 it works fine)
Does it mean I can't use any longer any non-latin character in my
String-s? WTF?
PS: The file ("zrzutnik.rb") is encoded all in utf-8 (without BOM).
Hello:
In Ruby 1.9.x you need to explicitly specify the encoding of your
strings to fit your requirements. Your default string encoding appears
to be US-ASCII (mine is CP850). If you want it to be UTF-8 use the
following to force the string to that encoding:
James Edward Gray II wrote an excellent blog on the topic here Gray Soft / Not Found .
Michael
Your proposition will not work, because it first requires a valid characters between "". Also, what if they come from external file?
One thing which bugs me yet else is does Ruby have got some core settings? I use UTF-8 very often so it might be a better solution (as for my thought) to set it as a default encoding instead of US-ASCII. Most Ruby-Gems in the Internet are in English and it fits pretty good with UTF-8 (in addition if some Gem is not in English an author probably have do some preparation to tell Ruby a right encoding). As I read in other's responses, the default encoding varies so I don't think my setting for US-ASCII was done on propose for some convention.