回答編集履歴

1

追記

2019/11/25 15:43

投稿

asm
asm

スコア15149

test CHANGED
@@ -13,3 +13,105 @@
13
13
 
14
14
 
15
15
  この2行をスクリプトの頭につけると大抵の場合うまく行きます。
16
+
17
+
18
+
19
+ ---
20
+
21
+
22
+
23
+ 簡単なテストですが
24
+
25
+
26
+
27
+ ```ruby
28
+
29
+ fruits = {
30
+
31
+ 'apple' => 'りんご',
32
+
33
+ 'banana' => 'バナナ',
34
+
35
+ 'grape' => 'ぶどう',
36
+
37
+ }
38
+
39
+
40
+
41
+
42
+
43
+ same = __ENCODING__
44
+
45
+ other = same == Encoding::UTF_8 ? "cp932" : "utf-8"
46
+
47
+
48
+
49
+ puts <<~EOS
50
+
51
+ __ENCODING__ = #{__ENCODING__}
52
+
53
+ default_internal = #{Encoding.default_internal}
54
+
55
+ default_external = #{Encoding.default_external}
56
+
57
+ "あ".inspect.encoding = #{"あ".inspect.encoding}
58
+
59
+ EOS
60
+
61
+
62
+
63
+ puts fruits
64
+
65
+
66
+
67
+ puts "-" * 50
68
+
69
+ Encoding.default_internal = other
70
+
71
+ Encoding.default_external = same
72
+
73
+
74
+
75
+ puts <<~EOS
76
+
77
+ __ENCODING__ = #{__ENCODING__}
78
+
79
+ default_internal = #{Encoding.default_internal}
80
+
81
+ default_external = #{Encoding.default_external}
82
+
83
+ "あ".inspect.encoding = #{"あ".inspect.encoding}
84
+
85
+ EOS
86
+
87
+
88
+
89
+ puts fruits
90
+
91
+
92
+
93
+ puts "-" * 50
94
+
95
+ Encoding.default_internal = same
96
+
97
+ Encoding.default_external = other
98
+
99
+
100
+
101
+ puts <<~EOS
102
+
103
+ __ENCODING__ = #{__ENCODING__}
104
+
105
+ default_internal = #{Encoding.default_internal}
106
+
107
+ default_external = #{Encoding.default_external}
108
+
109
+ "あ".inspect.encoding = #{"あ".inspect.encoding}
110
+
111
+ EOS
112
+
113
+
114
+
115
+ puts fruits
116
+
117
+ ```