Project

General

Profile

Bug #5176 » test.rb

hannibal (Masafumi Kiribayashi), 08/09/2011 05:17 PM

 
1
# coding: cp932
2
require 'psych'
3
require 'yaml'
4
#Encoding.default_internal = Encoding::CP932
5

    
6
=begin
7
module Psych
8
  module Visitors
9
    class YAMLTree
10
      alias :_visit_String :visit_String
11

    
12
      def visit_String o
13
        _visit_String(o.encode(Encoding::UTF_8))
14
      end
15
    end
16
  end
17

    
18
  module Nodes
19
    class Node
20
      alias :_to_yaml :to_yaml
21

    
22
      def to_yaml io = nil
23
        _to_yaml(io).tap {|v| v.force_encoding(Encoding::UTF_8) if v.kind_of?(String) }
24
      end
25
    end
26
  end
27
end
28
=end
29

    
30
v = {"a"=>"??"}
31
s = YAML::dump(v)
32
v = YAML::load(s)
33
puts v["a"].encode(Encoding.locale_charmap)