问题描述:

I am trying to open a file and store the contents as useable input for my methods in a separate file. Specifically, I have one file "test_int_file.rb", which simply has one integer on each line. I would like to use each integer as input into my method.

I have attempted to open this file using this command in the same file where my methods are stored:

File.open("/Desktop/Programs/test_int_file.rb")

My plan was then to use something like the following to get each line as a separate integer input (stored in an array) that I can pass to my method:

file_arr = []

File.open("/Desktop/Programs/test_int_file.rb").each_line do |line|

file_arr << line.to_i

end

So Two Main Questions HERE:

1) When I attempt the File.open("/Desktop/Programs/test_int_file.rb") on my Mac, I get this error in my terminal:

unknown regexp options - Prgra

What am I doing wrong in opening this file?

2) Will the block of code above work to get my input file of integers into an array of integers?

Thanks in advance!

相关阅读:
Top