On 4/7/07, Alexandre Rosenfeld <airmind / gmail.com> wrote:
> Thank you all for the answers. I really liked the solution below. It can
> handle a lot of the things I want to do. I can set overwrite to true as
> default for instance.

> Gavin Kistner wrote:

> > Here's one way:
> >
> >   def dosomehomework( directory, options={} )
> >     if options[:overwrite] then
> >       ...
> >   end

Keep in mind that if you want to set defaults, you probably want to do
it something like this:

def dosomehomework(directory, options={})

   options = {
       :overwrite => true,
       :otheroption => :default_value
   }.merge(options)
...
}

Instead of:

def dosomehomework(directory, options={ :overwrite => true,
:otheroption => :default_value })
...

In the second case, if the user specified any option it would wipe out
all of the defaults.

-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/