TrueClass === TrueClass

B

Bojan Mihelac

Hi all,
why is:

TrueClass === TrueClass # false
Object === Object # true

Documentation states that === method is used to provide meaningful
semantic in case statements. Can anyone explain me why some classes
returns false?

thnx,
Bojan Mihelac
 
V

Vincent Fourmond

Bojan said:
Hi all,
why is:

TrueClass === TrueClass # false
Object === Object # true

Documentation states that === method is used to provide meaningful
semantic in case statements. Can anyone explain me why some classes
returns false?

=== returns true with one class if you 'compare' it to an instance of
the class:

irb(main):002:0> TrueClass == TrueClass
=> true
irb(main):003:0> TrueClass === TrueClass
=> false
irb(main):004:0> TrueClass === true
=> true

Cheers,

Vince
 
D

David Chelimsky

=== returns true with one class if you 'compare' it to an instance of
the class:

irb(main):002:0> TrueClass == TrueClass
=> true
irb(main):003:0> TrueClass === TrueClass
=> false
irb(main):004:0> TrueClass === true
=> true

Cheers,

Ah - so Object === Object returns true because the second Object is an
instance of the first Object. How deceiving.
 
B

Bojan Mihelac

Vincent said:
=== returns true with one class if you 'compare' it to an instance of
the class:

irb(main):002:0> TrueClass == TrueClass
=> true
irb(main):003:0> TrueClass === TrueClass
=> false
irb(main):004:0> TrueClass === true
=> true

Cheers,

Vince

Thanx Vince, just what I looked for.
Bojan
 
D

David Chelimsky

If you are looking for a language in which not everything is an object,
there are plenty around ;)

Oh, you misunderstand. Let me rephrase:

"How deliciously deceiving."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,222
Messages
2,571,142
Members
47,757
Latest member
PDIJaclyn

Latest Threads

Top