Ruby: command line arguments

To read arguments like this:

$ ./test.rb “test1 test2”

use code like this to iterate over the ARGV array and print out its contents.

#!/usr/bin/env ruby

ARGV.each do|a|

  puts “Argument: #{a}”

end

http://ruby.about.com/od/rubyfeatures/a/argv.htm

or see OptionParser. More here:

http://stackoverflow.com/questions/4244611/pass-variables-to-ruby-script-via-command-line

Leave a Reply

Your email address will not be published. Required fields are marked *