622
know the features of your language
(lemmy.world)
Post funny things about programming here! (Or just rant about your favourite programming language.)
Yeah, you're quite correct, it's not exactly equivalent, I just went on auto-pilot because it's used so much for that purpose ๐ค
It's much closer to being a true null-coalescing operator than 'OR' operators in other languages though, because there's only two values that are falsy in Ruby:
nil
andfalse
. Some other languages treat0
and""
(and no doubt other things), as falsy. So this is probably the reason Ruby has never added a true null-coalescing operator, there's just much fewer cases where there's a difference.It's going to drive me mad now I've seen it, though ๐ That's usually the case with language features, though, you don't know what you're missing until you see it in some other language!