views:

51

answers:

1

Hi

How can i parse arguments separated by comma in ruby?

For example:

$> Main.rb --xmlid 1,2,3,4,5

I want to parse and store 1,2,3,4,5 in an array.

How can I do that?

Thanks.

+1  A: 

Once you know the index in ARGV of the list (in this case 1), use:

ARGV[index].split(',') #=> ["1", "2", "3", "4", "5"]
Adrian
+1 Should work as long as there are no spaces in the list of numbers while invoking the program.
Gishu