Actions
Feature #20756
closedIntroduce Boolean class
Status:
Rejected
Assignee:
-
Target version:
-
Description
Hello All,
Is is possible to add a parent class for TrueClass
and FalseClass
?
I always found it strange that there was not a concept to group true
and false
together.
e.g.:
class TrueClass < Boolean ; end
class FalseClass < Boolean ; end
# replaces the hack:
module Boolean ; end
TrueClass.include(Boolean);
FalseClass.include(Boolean);
In our code, we often want to validate that a value is of a certain type.
case(value)
when String ...
when Integer ...
when true, false ... # Boolean
# alt: when TrueClass, FalseClass
end
# or
def valid_args?
value.kind_of?(String)
end
def valid_args?
value.kind_of?(Integer)
end
def valid_args?
[true, false].include?(value)
[TrueClass, FalseClass].detect { |klass| value.kind_of?(klass) }
end
Does it make sense to others to have a way to group true
and false
together?
Thank you for your thoughts,
Keenan
Actions
Like0
Like0Like0Like0Like0Like0