So I am trying to read a file in ruby by giving the name via the command line. So far my code reads as follows:
puts "What is the name of the file to read?"
fileName = gets.chomp
file = $stdin.read.strip
f = File.open(file, “r”)
f.each_line { |line|
puts line
}
What I see happening is it is reading the inputs through the command line but does not read a file. For example, I can pass 'input.txt', 'code.txt', and 'sonic.txt' as file names but the program just loops back seeking another input. How can I change this to read the file by name and then out put the contents of that file?
fileName = gets.chompfor?fileNameis not used anywhere.