I kept running to this unexpected error token. I wanted the program to run without invoking ruby. For instances, instead of ruby program1.rb
, i should be able to program1.rb poem.txt
.
This is the error message:
program1.rb --backwards poem.txt
./program1.rb: line 1: syntax error near unexpected token `('
./program1.rb: line 1: `def backlines(line_array)'
This is my code:
def backlines(*line_array)
end
def backwards(line_array)
end
def backchars(line_array)
end
def main
file = File.new(ARGV[1], "r") do |file|
line_array = file.readlines
*line_array = line_array.reverse
if ARGV[0] == "--backlines"
*backwards_poem = backlines(line-array)
#you can manipulate "backwards_poem" however you want
elsif ARGV[0] == "--backwards"
backwards(line_array)
elsif ARGV[0] == "--backchars"
backchars(line_Array)
end
# passing a *line_array into a function
end
main