Hash as arguments of a method call

Hi all,

I'm writing a new class, and in the initialize I have:
class Statement
  def initialize(*args)
    @args = args[0]
    @args[:start_at] = 30.days.ago if @args[:start_at].nil?
    @args[:finish_at] = Date.today if @args[:finish_at].nil?
    @customer = Customer.find(@args[:customer_id])



This allows me, as you can see, to use @args[:customer_id] for example
to read arguments passed to the initialize. This is helpful in case I
need to add some more arguments to my method without breaking existing

This code is currently working (did not test it very long).

My question is: Why do I have to do the @args = args[0] thingy? I
mean, I noticed that args was an Array instead of a hash, so thats why
I did it. Is this correct? It doesnt look good...


I just read somewhere on AWDWR that the * makes it so that it accepts
every argument passed, generating an array.

So I thought that if I used method(args) it would accept only one arg

Thanks once again Ryan!

That's what *args does: it collects all the arguments into an array. If your method takes as a single argument a hash of options, then why bother with the *args ?