From: Robert Klemme Date: 2012-05-31T01:47:01+09:00 Subject: Re: Newbie question: command line to execute a method from .rb file On Wed, May 30, 2012 at 6:26 PM, n/a n/a 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 >  puts "Here we are - func1" > end > > def fonction2 >  puts "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) >  countArgs = 0; >  arg.each {|param| >    t[countArgs] = param >    countArgs = countArgs+1 >  } >  countArgs = 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. >  puts "You called me with #{count-args} argument(s) as parameters" > >  return 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 -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/