Ruby 1.9 String Encoding (WIP)
800 ワード
" ".force_encoding("GBK") == " " #>> false
"Hello".force_encoding("GBK") == "Hello" #>> true
" ".force_encoding("GBK") <=> " " #>> 1
"Hello".force_encoding("GBK") <=> "Hello" #>> 0
s1 = "a" + "b"
s2 = :a.to_s + "b"
s3 = :a.to_s + " "
s1.encoding.name #>> "UTF-8"
s2.encoding.name #>> "US-ASCII"
s3.encoding.name #>> "UTF-8"
irb:
puts "hello".encoding #>> 'UTF-8'
ruby test.rb:
puts "hello".encoding #>> 'US-ASCII'