Reputation: 191
I'm new to programming and started with Ruby through the Learn Ruby The Hard Way book. I'm on exercise 13 and am just fiddling around with utilizing ARGV and gets.chomp in the same script. My code is as follows:
first, second, third = ARGV
puts "Your first variable is: #{first}"
puts "Your second variable is: #{second}"
puts "Your third is: #{third}"
print "Was that so difficult?"
answer = gets.chomp
print answer
Obviously this isn't that difficult of a script, but when I run it it I keep getting this error: "ex13.rb:in 'gets': No such file or directory @ rb_sysopen - 'it then prints the first argv the user inputs when starting the script' (Errno::ENOENT) from ex13.rb:8:in 'gets' from ex13.rb:8:in "
Any help would be appreciated.
Upvotes: 5
Views: 1338
Reputation: 80065
That is what gets
does. Quoting: "(gets
) Returns (and assigns to $_) the next line from the list of files in ARGV (or $*), or from standard input if no files are present on the command line."
You could use $stdin.gets
, or make sure ARGV is empty: ARGV.clear
before using gets
.
Upvotes: 7