It's been a while since I've touched Ruby, but I think the stance was that only false and nil should be falsey? Which is not an unreasonable stance to take. The fewer falsey values, the easier it is to predict the behaviour. It's just surprising when coming from other languages.
Just off the top of my head, PHP treats "0", that is, specifically a string with a single zero, as falsey. Which has clearly gone too far to the other extreme.
It's not that you couldn't convert between types, it's that it wouldn't be automatic. You would need to actively call toboolean on a value before using it as a boolean, and the idea behind that is that intentionally casting the value leads to fewer mistakes
456
u/deceze 23h ago
It's been a while since I've touched Ruby, but I think the stance was that only
falseandnilshould be falsey? Which is not an unreasonable stance to take. The fewer falsey values, the easier it is to predict the behaviour. It's just surprising when coming from other languages.Just off the top of my head, PHP treats
"0", that is, specifically a string with a single zero, as falsey. Which has clearly gone too far to the other extreme.