```2009/8/20 Robert Klemme <shortcutter / googlemail.com>:
> 2009/8/20 Brian Candler <b.candler / pobox.com>:
>> Robert Klemme wrote:
>>> As a side note: I see this sometimes
>>>
>>> def m(a =3D nil)
>>> =A0 @a =3D a.nil? ? 123 : a
>>> end
>>>
>>> which is of course silly. =A0The same would be much better expressed as
>>>
>>> def m(a =3D 123)
>>> =A0 @a =3D a
>>> end
>>
>> No, it's not the same.
>
> Can you explain what the differences are?
>
>> Consider:
>>
>> =A0def foo(a =3D nil)
>> =A0 =A0m(a)
>> =A0end
>>
>> =A0foo()
>
> I do not see the connection of this to what I posted.

Argh!  Now I see what you mean.  If you use nil as universal "absence"
marker then you have to declare the default only inside the method
when doing the a.nil? logic because you will pass it through from
calling methods.

I only considered a single method and did not have nested calls in
mind.  Do you believe that these are common enough to warrant making
this a common pattern?

Btw, we can also do this:

def foo(*a)
bar(*a)
end

def bar(a =3D 123)
@a =3D a
end

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

```