Issue #12515 has been updated by Samuel Williams.


> Why do you use Kernel::Boolean and not just Boolean?

Some gems define

~~~
class Boolean
end

class TrueClass; include Boolean; end
class FalseClass; include Boolean; end
~~~

and some gems define:

~~~
module Boolean
end

class TrueClass; include Boolean; end
class FalseClass; include Boolean; end
~~~

If we defined our own `class Boolean` it would conflict with users (not that many) who are defining `module Boolean`. So, instead we define `Kernel::Boolean`. It's just one option. A simple way of understanding that is that `Kernel` is kind of a top level scope for name resolution.

Personally I don't think it's important in this case, people defining `module Boolean` in the global scope are categorically doing the wrong thing, but that's just my opinion. So, the sample implantation I gave works, does not collide with any existing implementation and would be perfectly suitable going forward, where in Ruby 3 it could be renamed to `class Boolean` and all people have received sufficient warning.

> It's just one of the issues, but it's the one backed by the same numbers you seem to think are the be-all and end-all.

The numbers are really just there to support the hypothesis that lots of people are working around the lack of `class Boolean` in core. The main issue here being a lack of consistency with other data types and specifically `x.is_a? Boolean`. Lot of people are doing this - there can be no disagreement here. It's an implementation detail whether methods are defined on `class Boolean` or `class TrueClass` and `class FalseClass` so Matz' argument does not resonate with me. I'm not arguing about implementation. I'm simply supporting moving into Ruby core what is already standard practice by 2 million examples.


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

* Author: Loren Segal
* Status: Rejected
* 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>