Oliver Peng wrote:
> Ruby will always use ASCII-8BIT as encoding when you use String.new to 
> create a new String object.

Ugh. That's another special case to add to
http://github.com/candlerb/string19/blob/master/string19.rb

However in practice it doesn't matter much, because the empty string is 
compatible.

irb(main):001:0> s1 = String.new
=> ""
irb(main):002:0> s2 = "gro"
=> "gro"
irb(main):003:0> s1.encoding
=> #<Encoding:ASCII-8BIT>
irb(main):004:0> s2.encoding
=> #<Encoding:UTF-8>
irb(main):005:0> s1 + s2
=> "gro"

And as for this which you found:

irb(main):003:0> s = "%c%c%c%c%c".force_encoding("US-ASCII")
=> "%c%c%c%c%c"
irb(main):004:0> t = s % [49, 5, 245, 225, 1]
=> "1\x05\xF5\xE1\x01"
irb(main):005:0> t.encoding
=> #<Encoding:US-ASCII>

I think it's just one of the many bugs in ruby 1.9.x, likely due to a 
total lack of specification of the new behaviour for all methods which 
accept or return strings (although if there's no specification, I 
suppose you can't really argue it's a bug; it can behave however it 
likes)
-- 
Posted via http://www.ruby-forum.com/.