teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

コードの修正

2016/02/13 12:21

投稿

K_S_
K_S_

スコア419

answer CHANGED
@@ -1,15 +1,20 @@
1
1
  ```Ruby
2
2
  ary=[]
3
3
  hash_ary=[]
4
+ loop_count = 0
4
5
  File.open("humans.csv","r") do |f|
5
6
  f.each_line do |line|
7
+ if loop_count == 0 then
8
+ next
9
+ end
6
- ary = line.chomp.split(",")
10
+ ary = line.chomp.split(",")
7
- hash_ary_c = {}
11
+ hash_ary_c = {}
8
- hash_ary_c["namae"]=ary[0]
12
+ hash_ary_c["namae"]=ary[0]
9
- hash_ary_c["seibetu"]=ary[1]
13
+ hash_ary_c["seibetu"]=ary[1]
10
- hash_ary_c["toshi"]=ary[2]
14
+ hash_ary_c["toshi"]=ary[2]
11
- hash_ary.push(hash_ary_c)
15
+ hash_ary.push(hash_ary_c)
16
+ loop_count += 1
12
- end
17
+ end
13
18
  end
14
19
 
15
20
  p hash_ary