I personally don’t see a compelling reason to introduce it, and I think the burden of proof goes in that direction. Erring on the side of not adding something is much more maintainable than the other way around. I do agree that it seems weird to have this thing in only String
that also leaks into Nil
, but I still don’t think that’s a strong enough argument to implement it widely in the standard library.
My main hang-up with this is that it makes the code potentially (and barely) more readable for Ruby devs at the expense of readability for people who don’t have that background (like me). Your example,
my_var = my_var.presence || ["default", "array"]`
isn’t very clear to me. If this were introduced (and I hadn’t read this thread), the following inner monologue seems pretty likely to me: ‘“Presence”? What does that mean? That it’s “there”? Well, if it isn’t “there” already, wouldn’t it just be Nil
? Why not just use #nil?
?’ Obviously, “this syntax doesn’t make perfect sense to me” isn’t the most persuasive argument, but my point is that a semantic that you’re used to isn’t necessarily one that most people will find intuitive if they don’t have your background.