回答編集履歴
2
修正
answer
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
```Ruby
|
2
2
|
str = "hoge: hogehoge|fuga: fugafuga|piyo: 999"
|
3
3
|
|
4
|
-
p str.split('|').map{|e| e.split(':')}.to_h
|
4
|
+
p str.split('|').map { |e| e.split(': ') }.to_h
|
5
5
|
```
|
6
|
-
考えてみました。
|
6
|
+
考えてみました。
|
7
|
+
|
8
|
+
参考にしたページ
|
9
|
+
[[Ruby] each_with_objectもmapも使わずにto_hだけで配列をハッシュに変換する](https://techracho.bpsinc.jp/hachi8833/2016_11_30/29584)
|
10
|
+
[配列からハッシュを作成する](http://www.rubylife.jp/ini/hash_class/index7.html)
|
1
修正
answer
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
```Ruby
|
2
2
|
str = "hoge: hogehoge|fuga: fugafuga|piyo: 999"
|
3
3
|
|
4
|
-
p str.split('|').map{|e| e.split(':
|
4
|
+
p str.split('|').map{|e| e.split(':')}.to_h
|
5
5
|
```
|
6
6
|
考えてみました。
|