On Tue, Aug 18, 2009 at 11:37 PM, Intransition<transfire / gmail.com> wrote:
> Messing with optional argument check for the umpteenth time, eg.
>
>  ¨Âåæ íåôè¨á½Åøãåðôéïî>  ¨Â¡½ Åøãåðôéï> ...
>  ¨Âìó> ..
>  ¨Âîä
>  ¨Âîä
>
> Other's might do:
>
>  ¨Âåæ íåô訪á©
>  ¨Â¡á®åíðôù>  ¨Â á®æéòó> ...
>  ¨Âìó> ..
>  ¨Âîä
>  ¨Âîä
>
> 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...
>
>  ¨Âåæ íåôè¨á½äåæáõìô>  ¨Âèáóßáòçõíåîôó¿
> ...
>  ¨Âìó> ..
>  ¨Âîä
>  ¨Âîä
>
> Ah... now that would be nice.

I've never felt the need for this.

Normally I just make the default value for an optional parameter nil,
and check for nil.

If nil is a valid value, then I'd do something like

class A

    MissingArgument = Object.new

   def meth(a=MissingArgument)
       if a == MissingArgument
       else
       end
   end
end




-- 
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale