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
>
>
> def test(*arg)
> =A0countArgs =3D 0;
> =A0arg.each {|param|
> =A0 =A0t[countArgs] =3D param
> =A0 =A0countArgs =3D countArgs+1
> =A0}
> =A0countArgs =3D countArgs+1
> =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"), ...
>
>
> I tried ruby test.rb test() , but of course, this isn't it.
>
> Let me know if I'm totally out of the concept here ?!

In the program you wrote, you are just defining the functions, but you
are not calling them
You need a section at the end that actually calls the test method, you
cannot do it from the outside (well, you can, but it's not probably
what you mean). If you want to pass to the test method any arguments
you write on the command line you can do this:

test(*ARGV)

and call it like this:

ruby test.rb 1 2 3 4

Little example:

def test *args
  p args
end

test(*ARGV)

$ ruby test.rb 1 2 3 4
["1", "2", "3", "4"]

Hope this helps,

Jesus.

PS: if you don't really want to call the test method inside your
script, you can do:

ruby -I. -rtest -e "test(1,2,3,4)"

but I'm guessing this is not what you really want.