Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created February 24, 2012 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenderlove/1902995 to your computer and use it in GitHub Desktop.
Save tenderlove/1902995 to your computer and use it in GitHub Desktop.
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment