This might be hard to explain, but I'll try.
Let's say I have a text file containing:
variable one
I'm variable 2
300
False
I am variable 5
Let's assume that I have multiple files like this and I don't know what is in each file. I want to take each line in the file and put it into a variable.
For example, this file would become these variables (which I can sort into strings, numbers and booleans with if
statements):
var1 = "variable one"
var2 = "I'm variable 2"
var3 = 300
var4 = False
var5 = "I am variable 5"
I want to make sure that this can be applied to any file with any number of lines.
Here's an example of what I hope the code would look like:
File.open("file.txt").each do |line|
var.new = "var" + line.line_number #creates new variable named "var" and the line number
var = line
end
I hope someone understands and knows how to do this because I'm completely stumped. I feel like there's some sort of really simple solution here that everybody commonly knows and I'm missing it or I just don't know it.
Thanks, Reece