public
Created

  • Download Gist
test.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# encoding: shift_jis
 
require 'yaml'
 
hello = "こんにちは!"
string = "--- #{hello}"
 
# psych 1.2.2 で例外発生するけど、ruby trunk は例外発生しない:
loaded = YAML.load string
 
# これで psych 1.2.2 を使える:
loaded = YAML.load string.encode('UTF-8')
 
p loaded.encoding # => Encoding:UTF-8
p loaded == hello # => false
 
Encoding.default_internal = Encoding::SHIFT_JIS
 
loaded = YAML.load string
p loaded.encoding # => Encoding:Shift_JIS
p loaded == hello # => true

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.