From: Simon Strandgaard Date: 2004-04-03T01:34:21+09:00 Subject: Re: parent of TrueClass, FalseClass On Fri, 02 Apr 2004 09:24:45 -0700, Ara.T.Howard wrote: > On Fri, 2 Apr 2004, Yukihiro Matsumoto wrote: > >> Hi, >> >> In message "parent of TrueClass, FalseClass" >> on 04/04/02, "Ara.T.Howard" writes: >> >> |any good reason these would not have a common parent Bool or something? >> >> Is there any good reason to have a common parent Bool, where true and >> false are only representations values of truth. >> >> matz. > > well - no, except that i'm sure alot of code would break if we pulled out > TrueClass and FalseClass. i guess you surely could have something like > > class Bool > TRUE = new > FALSE = new > ... > end > > if done from the start this would make some sort of sense. i just find it a > bit suprising that true and false, which are both representations values of > truth, are not related in anyway (duck type, module inclusion, parent class, > etc) and it is difficult (verbose) in ruby code to ask > > "is this a truth value" > > i realize ruby is moving more towards duck typing. but considering that - how > to you duck type a truth value? i mean, which method must something > respond_to? in order to be a bool? could it be useful if there was one? > > class Foo > include Truth > > def initialize arg > @bar = true if arg == 42 > end > > def truth # all logical operations derived from this > true unless @bar > end > end > > xor = Foo.new(0) ^ Foo.new(42) > How about (untested) Then it would be easy to add a Maybe class ;-) server> cat a.rb module Boolean class Base include Singleton end class True < Base def to_s; "true" end end class False < Base def to_s; "false" end end end # module Boolean TRUE = Boolean::True.instance FALSE = Boolean::False.instance server> -- Simon Strandgaard