Ex13 combining ARGV and gets.chomp

Hi all - following the exercises but keep getting an error when I try and combine the ARGV and gets.chomp the code and result are here:

first, second, third = ARGV # after we type the name of the programme we must then provide the three variables

puts “your first variable is #{first}”
puts “Your second variable is #{second}”
puts “Your third variable is #{third}”

puts “Give me another fruit”

fruit = gets.chomp
puts “and the last fruit is #{fruit}”

PS C:\Users\Study\documents\ruby> ruby ex13.rb oranges apples bananas
your first variable is oranges
Your second variable is apples
Your third variable is bananas
Give me another fruit
Traceback (most recent call last):
2: from ex13.rb:11:in <main>' 1: from ex13.rb:11:in gets’
ex13.rb:11:in `gets’: No such file or directory @ rb_sysopen - oranges (Errno::ENOENT)

What am I doing wrong?

Check out study drill 3 in that lesson and see if it’s helps :wink:

Thanks but solved it now with the help of my son! Evidently gets will try and use Kernel#gets which first tries to read the file passed through ARGV, hence the conflict but using STDIN.gets.chomp solves that conflict.

Happy to hear that! Your comment made mine.

A free service run by Zed A. Shaw for learncodethehardway.org.