I have written a ruby program in which it takes the input as url and it displays the components in it. I passed the URL inside the ruby file but now I want to pass it through ruby command line like ruby filename.rb url. How to pass an argument inside the code.
Asked
Active
Viewed 390 times
1
-
I believe this should help you out. http://stackoverflow.com/questions/4244611/pass-variables-to-ruby-script-via-command-line – Almaron Apr 01 '15 at 20:51
3 Answers
0
The ARGV
constant holds an array which contains all of the arguments passed in on the command line. So in your script, you could get the url passed in via ARGV[0]
.

Mason
- 703
- 6
- 20
0
ARGV is an array which contains all the arguments passed into your script via the command line.
ARGV.each do|arg|
puts "Argument: #{arg}"
end

Junior Joanis
- 345
- 1
- 9
0
Just use ARGV
constant , you can puts ARGV.to_s
in log to see what`s in it , to helps you understand how to use it .

Zoker
- 3,849
- 1
- 12
- 12