Ruby の `Enumerable#all?` が empty array にたいして `true` を返す

[].all? => false が返ってもヨサソウなのに・・という疑問

チャットで聞いたりググったりして、数学的に正しい方向に倒している結果、今の挙動である true を返していることがわかった。

  • ruby's "any?" and "all?" methods behaviour on Empty Arrays and Hashes - Stack Overflow
    • So since the block never gets called, of course it never returns false or nil, thus all returns true.
  • Vacuous truth - Wikipedia, the free encyclopedia
    • For example, the statement "all cell phones in the room are turned off" will be true whenever there are no cell phones in the room. In this case, the statement "all cell phones in the room are turned on" would also be vacuously true, as would the conjunction of the two: "all cell phones in the room are turned on and turned off".
  • 自明性 (数学) - Wikipedia)
    • 証明の主要な部分は空でない集合の場合を考え、元を詳細に検査するであろう。集合が空の場合には、性質は自明にすべての元によって持たれている、なぜならば元がないからである。