2025-04-22 Ruby に Boolean クラスはない
よくあるRubyの勘違いとして、TrueClass
, FalseClass
があるので、BoolClass
みたいのがありそう?って思ったけどない。
過去に提案は何度かされているが Reject されている。
Rejected for several reasons:
- many gems and libraries had already introduced Boolean class. I don’t want to break them.
- true and false are the only representative of true-false values. In Ruby. nil and false are falsy values, and everything else is a true value. There’s no meaning for having a superclass of TrueClass and FalseClass as Boolean.
ref. Feature #20756: Introduce Boolean class - Ruby - Ruby Issue Tracking System
日本語:
いくつかの理由で却下されました:
- 多くの gem やライブラリがすでに Boolean クラスを導入しており、それらを壊したくなかったため。
- Ruby において、true と false が真偽値の唯一の代表です。nil と false は偽と見なされ、それ以外のすべての値は真とされます。そのため、TrueClass と FalseClass の共通のスーパークラスとして Boolean を持つ意味はありません。