On Oct 14, 11:31 ¨Βν¬ Κεξσ ΧιμμΌκεξσ®χι®®®ΐυξι­λοεμξ®δεχςοτεΊ
> luke gruber [2011-10-14 17:15]:> That way, the instance won't be available across classes and you
> > can just check if the argument responds_to :missing?
>
> or you can just do this:
>
> class A
>
> def b(c = d = true)  or some other truthy value
> if d
> puts 'no argument was given'
> else
> puts c
> end
> end
>
> end
>
> can't remember where i first saw it, but it works perfectly ;)

That's pretty cleaver, although it reads perhaps a bit too strangely.

What I have always done is.... obviously, if `nil` is not a valid
argument, then just use that.

  def b(a=nil)
    if a
      ...
  end

But if `nil` is valid then use `ArgumentError`, as that won't be a
valid argument in 99.99% (or so) cases anyway.

  def b(a=ArgumentError)
    if a == ArgumentError
      ...
  end

For the most robust solution, Ruby Facets defines a toplevel constant
called `NA`, the sole purpose of which is to fill in for cases such as
this.

  def b(a=NA)
    if a == NA
      ...
  end

That's my favorite, but it require's a dependency on Facets or copy
and pasting the extra code to one's project.

(hmm... it occurs to me that global `$NA` variable would be good to
have too so there's no namespace issues such as in a BasicObjcet
subclass)