I like your find-or-begin pattern, and I've used the or operator to pun that way before as well.
But just a note, the if x = ... is not a side effect unless the variable "x" already exists. There's not problem using that as a pun to get rid of lots of if nesting. Similarly if x &&= ... is very good for avoiding an if-cascade, albeit more obscure and perhaps less performant.
It's too bad there isn't a beautiful way to do monads or the thrush operator in Ruby.
Re:Using “and” and “or” in Ruby
by jamesbritt on Monday August 02, 2010 @04:35PM
(#1568960)
FWIW
user = User.find(...) and (
...
)
also works. I find it cleaner. But using begin/end means you can toss a `rescue` in there if you like.
JM2C...