如何在Ruby中逐行读取文件?

时间:2015-11-11 20:59:57

标签: arrays ruby file

我有这样的文件数据:

  productRankingOct12: [
  value: "LessPopularityEPC"
,
  value: "CtrEpcJob"
,
  value: "DeviceSpecificLPE"
]
guidedSearch: [
  value: false
,
  value: true
]

我想将这些行读入数组&存储它像

array[0] = productRankingOct12: [
array[1] = value: "LessPopularityEPC"

1 个答案:

答案 0 :(得分:0)

使用File.readlinesinherited from IO):

lines = File.readlines(filename)