On Fri, Oct 14, 2011 at 17:31, Jens Wille <jens.wille / uni-koeln.de> wrote:

> 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 ;)

Yes, of course!  That°«s the trick I saw too; checking if the optional
argument°«s default value was evaluated.

Here°«s a more general solution that allows you to set d to a value
independent of the desired default value for the argument:

def m(a = (d = true; nil))
  # d will be true if argument a wasn°«t specified
end

One easily forgets how expressive Ruby can be.  Or how easily it is to abuse it.

Thanks!