Newbie's question: getting parameters given to hello.rb file

hello,

given i have a programme “hello.rb” and i execute it in terminal like
this

./hello.rb lalala lala stuff

how do i get the “lalala lala stuff” into my programme?

thanks

L. Maiwald wrote:

hello,

given i have a programme “hello.rb” and i execute it in terminal like
this

./hello.rb lalala lala stuff

how do i get the “lalala lala stuff” into my programme?

thanks

The arguments are in the ARGV array. ARGV[0] is the first argument,
ARGV[1] the second, and so forth.

Tim H. wrote:

The arguments are in the ARGV array. ARGV[0] is the first argument,
ARGV[1] the second, and so forth.

thank you!

L. Maiwald wrote:

Tim H. wrote:

The arguments are in the ARGV array. ARGV[0] is the first argument,
ARGV[1] the second, and so forth.

thank you!

additionally, sometimes it’s helpful to know the number of arguments
sent in with

ARGV.size

when my shell-style ruby scripts are dependent on arguments, i include a
line at the top like this:

raise ‘usage: rubycat.rb file1 file2’ if ARGV.size == 0