Argv

I've never used argv before and am just curious about how it works, what I want to do is make a program that will take an argument when called, I've been told argv can do this. For example:

Say I have a program called prt_jobs

If I called prt_jobs tep

I want it to take the "tep" as an argument. How can I go about doing this?

···

Sent from my iPhone

http://lmgtfy.com/?q=ruby+ARGV+example

···

On 01/04/2016 17:14:57, thomas Perkins wrote:

I've never used argv before and am just curious about how it works, what I want to do is make a program that will take an argument when called, I've been told argv can do this. For example:

Say I have a program called prt_jobs

If I called prt_jobs tep

I want it to take the "tep" as an argument. How can I go about doing this?

Sent from my iPhone

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

--
Raj Sahae
408.230.8531

In general ARGV is an array of all arguments specified on the command line.
In your case, calling `prt_jobs tep` would result with ARGV equal to
["tep"].

However, in most cases, you want to use some kind of an option parser. The
Ruby standard library contains one (see
http://ruby-doc.org/stdlib-2.3.0/libdoc/optparse/rdoc/OptionParser.html\).
There are also toolkits for building CLI interfaces. Thor (
http://whatisthor.com/\) is an example.

So the question is: what are you trying to accomplish?

Best regards

···

--
Greg Navis

On Tue, Jan 5, 2016 at 12:14 AM, thomas Perkins <thomas.perkins23@icloud.com > wrote:

I've never used argv before and am just curious about how it works, what I
want to do is make a program that will take an argument when called, I've
been told argv can do this. For example:

Say I have a program called prt_jobs

If I called prt_jobs tep

I want it to take the "tep" as an argument. How can I go about doing this?

Sent from my iPhone

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;