回答編集履歴
3
修正
test
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
def to_hash(str)
|
4
4
|
|
5
|
-
str.scan(%r|"(.+?)"=>"(.+?)"|).map{|k, v|[k.to_sym, v
|
5
|
+
str.scan(%r|"(.+?)"=>"(.+?)"|).map{|k, v|[k.to_sym, v]}.to_h
|
6
6
|
|
7
7
|
end
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
hash = to_hash('{"apple"=>"
|
11
|
+
hash = to_hash('{"apple"=>"1", "banana"=>"ばなな"}')
|
12
12
|
|
13
13
|
|
14
14
|
|
2
修正
test
CHANGED
@@ -23,3 +23,11 @@
|
|
23
23
|
りんご
|
24
24
|
|
25
25
|
```
|
26
|
+
|
27
|
+
質問者様が配列だとおっしゃっているものは
|
28
|
+
|
29
|
+
配列ではないと思われます。
|
30
|
+
|
31
|
+
私の勉強不足かもしれませんが文字列ではないかと。
|
32
|
+
|
33
|
+
|
1
修正
test
CHANGED
@@ -8,6 +8,18 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
|
11
|
+
hash = to_hash('{"apple"=>"りんご", "banana"=>"ばなな"}')
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
puts hash[:apple]
|
12
16
|
|
13
17
|
```
|
18
|
+
|
19
|
+
実行結果例
|
20
|
+
|
21
|
+
```
|
22
|
+
|
23
|
+
りんご
|
24
|
+
|
25
|
+
```
|