Cool, sure, but blind rescues are as the crow flies to bugs: use them wisely, or use them _why-ly.
that's along the lines of using or for nil returns.
value = function_that_nils || "default"
I've found it makes code more succinct.
Careful here: I've seen plenty of "Rubiomatic" bugs that look like this:
value = function_that_nils or "default"
... which results in nil assignment to value. Accidental confusion between || and 'or' is very common in Ruby world IMO, almost like famous == vs = in C.
Agreed. I think one is for statements (or) and the other one is for expressions (||), so they have different operational precedence, even though you could use them interchangeably, as long as you knew what got executed first.
I'm not sure how this has been escaping me since 07, but I had no idea you can apply it at the end of an expression, i.e. when you're facing nasty functions that insist on trhowing exceptions, instead of
begin
rescue endyou can just write:
value = function_that_throws rescue "default"