From: matthew@... Date: 2016-10-31T23:48:40+00:00 Subject: [ruby-core:77844] [Ruby trunk Feature#12515] Create "Boolean" superclass of TrueClass / FalseClass Issue #12515 has been updated by Matthew Kerwin. Samuel Williams wrote: > > > There is no value in defining a Boolean superclass of both **TrueClass and FalseClass**. > > There is value in the check `x.is_a? Boolean`. The value is in the check itself, finding out if x contains [true, false]. And the value is in the consistency that there is a single class name "`Boolean` which is polymorphic over the set of classes `Integer`, `Float`, `Numeric`, `String`, etc, which are used over and over again in code which does formatting, type checking, serialisation, deserialisation, database modelling, etc. > You keep saying things like "polymorphic," but you still haven't answered the question which is fundamental to this whole debate: what method would you define on `class Boolean` that applies identically to both `TRUE` and `FALSE`? An object's `.class` is **not the same** as its type. If they never quack the same, they aren't ducks. A class that doesn't define a #quack method is not a useful class, in the Ruby sense. > > No other language structures booleans around a "TrueClass" and "FalseClass": > > - Python has `bool` data type. > - C has `#include ` > - C++ has `bool` > - Java has `bool` and `class Boolean` > - JavaScript has `Boolean` > - Smalltalk has `Boolean` > - CLISP has `BOOLEAN` > As has been mentioned already, `TrueClass` and `FalseClass` (and `NilClass`) are just named eigenclasses of the objects `TRUE` and `FALSE` (and `NIL`). There's no "structure" around them beyond the fact that *every* object (including the three listed above) has one; these three just happen to have a little quirk in their inheritance. Perhaps it would be better if `TRUE.class` (etc.) returned `Object`; being an instance of the eigenclass is rather confusing. > > but I say, "People already live with that possibility and seem to be surviving just fine." > > Is Ruby a language just to survive or is it a language to provide the tools programmers need to be happy? > (Semantics: "surviving just fine" implies satisfaction and comfort (i.e. happiness.) That notwithstanding:) The latter, if the "programmers" in question are Matz. Ruby isn't designed to make Java or C++ or 8086 programmers happy, it's designed for Ruby programmers. In Ruby class is not type, and type is defined by behaviour. You have to learn this if you want to be a happy Ruby programmer. ---------------------------------------- Feature #12515: Create "Boolean" superclass of TrueClass / FalseClass https://bugs.ruby-lang.org/issues/12515#change-61156 * 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: