News for hackers. Stuff that matters.
Re:Evil Ruby by philh on Wednesday January 23, 2013 @09:11AM (#5103051)
You might want a lookup method to usually throw an exception if it doesn't find anything, but sometimes return a user-specified default.

It's problematic though, because writing a thin wrapper becomes a pain in the ass.

Re:Evil Ruby by damncabbage on Wednesday January 23, 2013 @09:03PM (#5106661)
I'd argue that it's really two functions:

* One to do the lookup and potentially explode; this always takes an argument.

* A second to provide the default.

Have the caller call the appropriate one. User provides params[:search] (or some other "explicitly trying to search"), then call the first. If not, call the latter.