New String rules?

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

Am 16.01.2011 16:55, schrieb felix.leg:

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

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 = “The non-ascii string: Zdefiniowa nowy”

“felix.leg” [email protected] wrote in message
news:[email protected]

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 G. II wrote an excellent blog on the topic here
http://blog.grayproductions.net/articles/ruby_19s_string .

Michael

W dniu 16.01.2011 18:09, Michael B. pisze:

^
strings to fit your requirements. Your default string encoding appears
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.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs