From: Glenn Ritz on
Hi,

I want to create a Rails rake task that can accept a varying number of
arguments. Ideally, I'd like the arguments to be optional, and I'd also
like to be able to specify 1 or more.

So, if I have the rake task my_task, like this:

task :do_something, :arg1 do |t, args|
puts args.inspect
# some code goes here
end

I's like to be able to execute this like this:

rake do_something

rake do_something[1]

rake do_something[1, 2, 4]

I'd like args to be an empty array in the first call, a one element
array in the second, and a 3 element array in the third. I think 0
arguments or 1 is simple -- the way I've written the task above does
this much. But I don't know how to get it to accept more than 1. Is
there a way to do this?

Thanks.
--
Posted via http://www.ruby-forum.com/.