[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: case question

Caleb Tennis

1/10/2006 12:17:00 AM

>
> it must miss something
> Any ideas?
>
>

case comparisons are done using ===.

irb(main):017:0> nil.class === NilClass
=> false
irb(main):018:0> nil.class == NilClass
=> true

For classes/modules, it's used to determine if an instance is a
descendant:

irb(main):027:0> 5 === Fixnum
=> false
irb(main):028:0> Fixnum === 5
=> true

Caleb


2 Answers

Daniel Schüle

1/10/2006 2:34:00 AM

0

Caleb Tennis wrote:
>>
>> it must miss something
>> Any ideas?
>>
>>
>
> case comparisons are done using ===.
>
> irb(main):017:0> nil.class === NilClass
> => false
> irb(main):018:0> nil.class == NilClass
> => true
>
> For classes/modules, it's used to determine if an instance is a
> descendant:

nil.kind_of? NilClass

can I assume that === is in this context the same as kind_of?
or are there subtle differences between them

> irb(main):027:0> 5 === Fixnum
> => false
> irb(main):028:0> Fixnum === 5
> => true
>
> Caleb

thanks to both, this helps

Caleb Tennis

1/10/2006 1:16:00 PM

0


> can I assume that === is in this context the same as kind_of?
> or are there subtle differences between them

=== by default calls == unless you specifically override it in your
implementation.

Module overrides it (which means that Class overrides it as well).

I think it's probably safe to say that === is in the same context as kind_of?,
at least for classes:

irb(main):009:0> NilClass === nil
=> true
irb(main):010:0> nil === NilClass
=> false

Caleb