[Ruby 1.9] New String rules?

F

felix.leg

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).
 
Q

Quintus

Am 16.01.2011 16:55, schrieb felix.leg:
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).

Put this in as the first line (or second if the file has a shebang):

#Encoding: UTF-8

Vale,
Marvin
 
Y

Y. NOBUOKA

Hi,

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 =3D "The non-ascii string: Zdefiniowa=E6 nowy"

--=20
nobuoka
 
M

Michael Brooks

felix.leg said:
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).

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:

abc = "abc"
puts abc.encoding.name # >> US-ASCII

abc.force_encoding("UTF-8")
puts abc.encoding.name # >> UTF-8

James Edward Gray II wrote an excellent blog on the topic here
http://blog.grayproductions.net/articles/ruby_19s_string .

Michael
 
F

felix.leg

W dniu 16.01.2011 18:09, Michael Brooks pisze:
felix.leg said:
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).

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:

abc = "abc"
puts abc.encoding.name # >> US-ASCII

abc.force_encoding("UTF-8")
puts abc.encoding.name # >> UTF-8

James Edward Gray II wrote an excellent blog on the topic here
http://blog.grayproductions.net/articles/ruby_19s_string .

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

Brian Candler

felix.leg wrote in post #975280:
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=C4=87
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
https://github.com/candlerb/string19/
(and click through to string19.rb)

I've found about 200 rules so far. I'm sticking with 1.8.

-- =

Posted via http://www.ruby-forum.com/.=
 

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,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top