Issue #12515 has been updated by Martin Drst.


Loren Segal wrote:

> This actually comes up fairly often:
> 
> https://github.com/search?p=2&q=is_a%3F+TrueClass&ref=searchresults&type=Code&utf8=%E2%9C%93
> 
> And that's only the checks for is_a? syntax, because GitHub cannot search for "TrueClass === x" style code. But if it's an anti-pattern, it's an extremely common one.

The search results aren't very convincing to me. Where there's a `Boolean` `class` or `module`, it's usually really tiny. And there are checks for `TrueClass` and `FalseClass` that I'd write as checks for `true` and `false`, which would make the code a lot shorter.

Actually, because both `true` and `false` are singletons, `TrueClass` and `FalseClass` look like overkill; in Ruby's ducktyping world, most if not all things would work just as well with the necessary methods for `true` and `false` being defined directly as singleton methods on `true` and `false`.


----------------------------------------
Feature #12515: Create "Boolean" superclass of TrueClass / FalseClass
https://bugs.ruby-lang.org/issues/12515#change-59337

* Author: Loren Segal
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Since Ruby 2.4 is unifying Bignum/Fixnum into Integer (https://bugs.ruby-lang.org/issues/12005), it seems reasonable to do something similar for TrueClass / FalseClass, and create a proper Boolean hierarchy. The implementation would be fairly straightforward and should be back compat unless someone already has a "Boolean" class at toplevel out there.

Given the compatibility implications of Integer, this Boolean proposal is even less intrusive.

Sample implementation:

~~~
class Boolean < BasicObject; end
class TrueClass < Boolean; end
class FalseClass < Boolean; end
~~~




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>