Reputation: 2140
I would like to know how to get the number of arguments pass with a ruby script. So far everything I searched for has been to functions.
I execute my script like this: ruby script.rb Arg1 Arg2 Arg3
Now I want to get the number of arguments, in this case it is 3. How can I do so?
I am using ruby1.9.3
EDIT: I want my code to look like:
#!/usr/bin/env ruby
# check number of arguments passed
.
.
.
Upvotes: 3
Views: 5714
Reputation: 1675
ARGV
contains all the arguments passed to the script, ARGV.length
is the number of arguments.
Upvotes: 8
Reputation: 62668
You're looking for the ARGV
array. It's just like any other array, but it's populated with a list of command line arguments passed.
http://ruby-doc.org/core-1.9.3/ARGF.html
Upvotes: 2