[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

TrueClass/FalseClass vs. Boolean

PrimaryKey

3/30/2006 9:31:00 PM

Greetings!

I am wondering why there are two separate classes (TrueClass and
FalseClass) to deal with boolean types insead of one class (something
like Boolean?). Do you know
why the library designer desided to use this approach?

Your help will be greatly apreciated.

Thanks

--
Posted via http://www.ruby-....


22 Answers

Eric Hodel

3/30/2006 9:43:00 PM

0

On Mar 30, 2006, at 1:31 PM, PrimaryKey wrote:

> Greetings!
>
> I am wondering why there are two separate classes (TrueClass and
> FalseClass) to deal with boolean types insead of one class (something
> like Boolean?). Do you know
> why the library designer desided to use this approach?
>
> Your help will be greatly apreciated.

This has been discussed many, many times before. Here's a reading list:

http://blade.nagaokaut.ac.jp/cgi-bin/vframe.rb?key...
+FalseClass&cginame=namazu.rb&submit=Search&dbname=ruby-
talk&max=50&whence=0

--
Eric Hodel - drbrain@segment7.net - http://blog.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...




baumanj

3/30/2006 9:43:00 PM

0

Since everything in ruby is an object, there need to be objects for
representing true and false. Once you have those, why do you need a
Boolean class?

PrimaryKey wrote:
> Greetings!
>
> I am wondering why there are two separate classes (TrueClass and
> FalseClass) to deal with boolean types insead of one class (something
> like Boolean?). Do you know
> why the library designer desided to use this approach?
>
> Your help will be greatly apreciated.
>
> Thanks
>
> --
> Posted via http://www.ruby-....

Florian Groß

3/31/2006 2:11:00 PM

0

Gary Wright

3/31/2006 3:14:00 PM

0


On Mar 31, 2006, at 9:27 AM, Christian Neukirchen wrote:
> case y
> when Integer
> when Boolean
> end

case y
when Integer
when TrueClass,FalseClass
end

works ok, right? I kind of wish the class names were just True and
False.


Gary Wright





Ara.T.Howard

3/31/2006 3:21:00 PM

0

baumanj

3/31/2006 3:38:00 PM

0

ara.t.howard@noaa.gov wrote:
> On Fri, 31 Mar 2006, Christian Neukirchen wrote:
> > if a.kind_of? Boolean
> >
> > case y
> > when Integer
> > when Boolean
> > end

What kind of scenarios would you want to use such a construct? It seems
to me not very rubyish to be switching based on the class of an object.
As I understand it, the more conventional way to deal with potentially
diverse argument types is to use the respond_to? method. This keeps the
door open for duck typing.

> another thing a real Boolean class could give is a 'maybe' obj such that
....
> although i can't think of anything attm to do with this it would undoubtably
> lead to some nice logical constructs that more closely parallel the way we
> think.

It sounds like you're talking about a sort of restricted fuzzy logic,
which is very cool, but is not appropriate for the core of a general
purpose language. Considering that every expression can be interpreted
in a boolean context, what would a maybe value do? Either behavior
seems wrong.

Ara.T.Howard

3/31/2006 4:17:00 PM

0

Christian Neukirchen

3/31/2006 5:25:00 PM

0

"baumanj@gmail.com" <baumanj@gmail.com> writes:

> ara.t.howard@noaa.gov wrote:
>> On Fri, 31 Mar 2006, Christian Neukirchen wrote:
>> > if a.kind_of? Boolean
>> >
>> > case y
>> > when Integer
>> > when Boolean
>> > end
>
> What kind of scenarios would you want to use such a construct? It seems
> to me not very rubyish to be switching based on the class of an object.
> As I understand it, the more conventional way to deal with potentially
> diverse argument types is to use the respond_to? method. This keeps the
> door open for duck typing.

Except we don't have a to_bool, either ;-).

Still, I can saw enough cases where I wanted such a "case", and
grumbly used TrueClass,FalseClass.

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...


Jim Weirich

3/31/2006 7:10:00 PM

0

unknown wrote:
> maybe or true -> maybe

Wouldn't maybe or true be true?

--
-- Jim Weirich


--
Posted via http://www.ruby-....


Gregory Seidman

3/31/2006 8:44:00 PM

0

On Sat, Apr 01, 2006 at 12:38:43AM +0900, baumanj@gmail.com wrote:
} ara.t.howard@noaa.gov wrote:
} > On Fri, 31 Mar 2006, Christian Neukirchen wrote:
} > > if a.kind_of? Boolean
} > >
} > > case y
} > > when Integer
} > > when Boolean
} > > end
}
} What kind of scenarios would you want to use such a construct? It seems
} to me not very rubyish to be switching based on the class of an object.
} As I understand it, the more conventional way to deal with potentially
} diverse argument types is to use the respond_to? method. This keeps the
} door open for duck typing.
[...]

The most obvious answer is that it is needed for various kinds of
serialization. I wrote something like this just the other day. I needed to
do XML-RPC serialization (yes, I know there is XML-RPC support in the
standard library, but I needed something slightly different that was easier
to do by hand), so I needed to know what kind of value I was serializing.

--Greg