Gavin Kistner
7/7/2007 2:51:00 PM
On Jul 6, 5:26 pm, Roger Pack <rogerpack2...@gmail.com> wrote:
> Variable parameter assignment in function calls. (sorry)
> i.e. the following:
> function_x(3,4,failure=true,options=false)
>
> (by default, not using hashes). This allows for more understandable
> code than
> function_x(3,4,true,true,1,true,false) # does anyone after 3 months
> remember what each of those MEANT? [note the true,false at the
> end--those were my "failure" and "options," from the first example].
I suspect you really mean named paramaters allowed in such a way that
you don't have to remember the order of parameters when calling the
method. However, I wanted to point out that what you wrote is legal,
and does address one of your points:
Slim2:~ phrogz$ irb
irb(main):001:0> def do_it( times=3, failure=true, options=false )
irb(main):002:1> p times, failure, options
irb(main):003:1> end
=> nil
irb(main):004:0> do_it( times=12, failure=false, options=false )
12
false
false
=> nil
You still need to pass the parameters in the correct order, but when
invoking the method there's nothing preventing you from assigning the
values to (dummy) local variables in the process as nice labels for
someone reading the code later.