From: "felix.leg" Date: 2011-01-25T20:21:11+09:00 Subject: Re: [Ruby 1.9] New String rules? W dniu 16.01.2011 18:09, Michael Brooks pisze: > > "felix.leg" 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: 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.