Ruby Command-Line Arguments


If you’re writing a serious Ruby application (not a Rails application necessarily), this question may apply to you: how do you access command-line arguments in Ruby?

Ruby provides an array called ARGV (all upper-case). This array contains all the command-line arguments; so if you run this:

ruby script.rb first second third

… then ARGV.length is 3, ARGV[0] is “first”, ARGV[1] is second, and ARGV[2] is third.

Tags: , ,     Posted in Development

Rate this article:
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Related Content


One Response to “Ruby Command-Line Arguments”

  1. deli Says:

    thx to write this.

Leave a Reply