```2009/8/19 Intransition <transfire / gmail.com>:
> Messing with optional argument check for the umpteenth time, eg.
>
> =A0def meth(a=3DException)
> =A0 =A0if a !=3D Exception
> =A0 =A0 =A0 ...
> =A0 =A0else
> =A0 =A0 =A0...
> =A0 =A0end
> =A0end

My 0.02 EUR: if your method's behavior changes depending on argument
or argument types chances are that you may rather want different
methods.

As a side note: I see this sometimes

def m(a =3D nil)
@a =3D a.nil? ? 123 : a
end

which is of course silly.  The same would be much better expressed as

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

There is no need for additional optional logic - at least in these simple c=
ases.

> Other's might do:
>
> =A0def meth(*a)
> =A0 =A0if !a.empty?
> =A0 =A0 =A0a =3D a.first
> =A0 =A0 =A0 ...
> =A0 =A0else
> =A0 =A0 =A0...
> =A0 =A0end
> =A0end
>
> Neither of which are very satisfying. So it occurs to me tonight that
> we already have #has_block? to see if a block was passed. So how about
> a #has_arguments? to query if _any_ arguments have been passed. So
> then...
>
> =A0def meth(a=3Ddefault)
> =A0 =A0if has_arguments?
> =A0 =A0 =A0 ...
> =A0 =A0else
> =A0 =A0 =A0...
> =A0 =A0end
> =A0end
>
> Ah... now that would be nice.

It may be useful in some cases but since you can always do the "trick"
with "*" I am not sure whether we really need this.  I always found
block_given? a bit awkward since it looks like a method of self but is
rather a quick way to get at information about the argument list.  The
only reason I use it at times is the fact that the combination m(&b)
b.call is slower than the combination m() yield.

I'm undecided really.

Kind regards

robert

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

```