-1

I have a file data like this:

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

I would like to read the lines into array & store it like

array[0] = productRankingOct12: [
array[1] = value: "LessPopularityEPC"
  • 6
    There are numerous posts about reading a file line by line. For example, [this one](http://stackoverflow.com/questions/5545068/what-are-all-the-common-ways-to-read-a-file-in-ruby). You can modify it slightly to load an array. – lurker Nov 11 '15 at 21:03
  • Your data file looks like no other I've ever seen. What's generating it? Are you *sure* that's how it actually looks? *WHY* do you want to read a file into an array? Is the file guaranteed to *always* fit into memory? Please read http://stackoverflow.com/questions/25189262/. – the Tin Man Nov 12 '15 at 00:39

1 Answers1

3

Use File.readlines (inherited from IO):

lines = File.readlines(filename)
Jordan Running
  • 102,619
  • 17
  • 182
  • 182