I am trying to read a file containing some numbers. And then I want to convert them into a whole. When I try, as shown below, this is normal.
input = IO.readlines(filename)
size = input[0].split(/\s/).map(&:to_i)
But, when I try, as shown below, it gives me this error.
input = IO.readlines(filename)
lnth = input.length
i=0
while i<=lnth
size = input[i].split(/\s/).map(&:to_i)
i=i+1
end
undefined `split 'method for nil: NilClass (NoMethodError)
How do I solve the error now?
source
share