Hacker News new | ask | show | jobs
by sethrin 842 days ago
Most often I do

  var_that_might_be_nil.presence || default
reads better imo
1 comments

"presence" isn't Ruby, but Rails/ActiveSupport and your example acts very differently in the case of empty strings, empty arrays, hashes etc..
yes, and?
So it's often a) not available, b) semantically not an alternative.

In particular it very specifically does not return the default only when the object is nil, and I have plenty of code where people thinking they're the same would cause serious breakage.