On Wed, May 30, 2012 at 6:26 PM, n/a n/a <lists / ruby-forum.com> wrote:
> Hi there -
>
> So, I'm sorry for this very basic question which makes me feel like a
> real dummy... But honestly I couldn't find the answer from many internet
> tutorials, nor from the book I am reading, called "Ruby: the
> foundations...".
>
> So, pretty basic, I have a test.rb file which contains:
>
>
> def fonction1
> =A0puts "Here we are - func1"
> end
>
> def fonction2
> =A0puts "Here we are - func2"
> end

Not sure what those functions are used or intended for - I cannot see
any invocation of them.

> def test(*arg)
> =A0countArgs =3D 0;
> =A0arg.each {|param|
> =A0 =A0t[countArgs] =3D param
> =A0 =A0countArgs =3D countArgs+1
> =A0}
> =A0countArgs =3D countArgs+1

This increment is too much. But you do not need to count manually
because you can get the count directly via args.size.

> =A0puts "You called me with #{count-args} argument(s) as parameters"
>
> =A0return t
> end
>
>
> Now, I'm still trying to figure out the COMMAND LINE to eventually
> execute my test() function of test.rb.
> I want to try on different cases, test(a,b,c), test("yoyo", "yaya"), ...

Well, if you want to do that just include those calls in the script:

test(a,b,c)
test("yoyo", "yaya")

> I tried ruby test.rb test() , but of course, this isn't it.

If you want to find out the arguments to the program, then this is easiest:

puts "You called me with #{ARGV.size} argument(s) as parameters"

Then just invoke it with

$ ruby your-script.rb arg1 arg2

If you want to use your method #test to evaluate program arguments you can =
do

test(*ARGV)

But I am not 100% sure I understood what you're after.

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/