I have an ASCII file that looks like:
1 0 3 0 4
4 3 2 9 8
3 0 9 9 7
I am able to store each whole line as an seperate array. But I cannot
find out how I can get the input of that file and store it into a double
array. For example, 1 would be array, and 7 would be array.
Are those spaces separating each item, or did you just put that in for
readability? No worries, it’s similar either way.
Assuming you’ve already used readlines() to read all the file’s lines
into an array you can then do this:
array.map! do |line| line.split // end
Splitting on an empty regexp divides a string into individual
characters. But for space-delimited characters you can just use the
default split using whitespace, which makes things even easier:
array.map! do |line| line.split end