Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Why Fixnum===Fixnum is false?

Reply
Thread Tools

Why Fixnum===Fixnum is false?

 
 
Heesob Park
Guest
Posts: n/a
 
      05-13-2009
Hi,

I noticed the following behaviour.

irb(main):001:0> a = 1
=> 1
irb(main):002:0> a.class
=> Fixnum
irb(main):003:0> a.class == Fixnum
=> true
irb(main):004:0> a.class === Fixnum
=> false
irb(main):005:0> Fixnum === Fixnum
=> false
irb(main):006:0> a === Fixnum
=> false
irb(main):007:0> Fixnum === a
=> true

As a result:

case 1
when Fixnum
puts 'Fixnum'
else
puts 'else'
end
# => Fixnum

case 1.class
when Fixnum
puts 'Fixnum'
else
puts 'else'
end
#=> else

What is the reason Fixnum === Fixnum returns false?

Regards,
Park Heesob

 
Reply With Quote
 
 
 
 
Joel VanderWerf
Guest
Posts: n/a
 
      05-13-2009

Fixnum is not an instance of Fixnum. Compare:

------------------------------------------------------------- Object#===
obj === other => true or false

From Ruby 1.8
------------------------------------------------------------------------
Case Equality---For class Object, effectively the same as calling
#==, but typically overridden by descendents to provide meaningful
semantics in case statements.

------------------------------------------------------------- Module#===
mod === obj => true or false

From Ruby 1.8
------------------------------------------------------------------------
Case Equality---Returns true if anObject is an instance of mod or
one of mod's descendents. Of limited use for modules, but can be
used in case statements to classify objects by class.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

 
Reply With Quote
 
 
 
 
Adam Gardner
Guest
Posts: n/a
 
      05-13-2009
Joel VanderWerf wrote:
> Fixnum is not an instance of Fixnum. Compare:
>
> ------------------------------------------------------------- Object#===
> obj === other => true or false
>
> From Ruby 1.8
> ------------------------------------------------------------------------
> Case Equality---For class Object, effectively the same as calling
> #==, but typically overridden by descendents to provide meaningful
> semantics in case statements.
>
> ------------------------------------------------------------- Module#===
> mod === obj => true or false
>
> From Ruby 1.8


Uh, I think you omitted the most important part of the documentation, to
whit, what it actually says about Module#===:

------------------------------------------------------------- Module#===
mod === obj => true or false
------------------------------------------------------------------------
Case Equality---Returns +true+ if _anObject_ is an instance of
_mod_ or one of _mod_'s descendents. Of limited use for modules,
but can be used in +case+ statements to classify objects by class.

(and incidentally, it is also important to know that the class 'Class'
does not define it's own #=== method, and so inherits from Module, which
is hinted at but not explicitly stated here)
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Joel VanderWerf
Guest
Posts: n/a
 
      05-13-2009
Adam Gardner wrote:
> Joel VanderWerf wrote:
>> Fixnum is not an instance of Fixnum. Compare:

...
> Uh, I think you omitted the most important part of the documentation, to
> whit, what it actually says about Module#===:


http://blade.nagaokaut.ac.jp/cgi-bin...by-talk/336430

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

 
Reply With Quote
 
Adam Gardner
Guest
Posts: n/a
 
      05-14-2009
Joel VanderWerf wrote:
> Adam Gardner wrote:
>> Joel VanderWerf wrote:
>>> Fixnum is not an instance of Fixnum. Compare:

> ...
>> Uh, I think you omitted the most important part of the documentation, to
>> whit, what it actually says about Module#===:

>
> http://blade.nagaokaut.ac.jp/cgi-bin...by-talk/336430


Huh, odd. Bug in Ruby-forum, then, I guess. Sorry.

( http://www.ruby-forum.com/topic/186753#815590 )
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Joel VanderWerf
Guest
Posts: n/a
 
      05-14-2009
Adam Gardner wrote:
> Joel VanderWerf wrote:
>> Adam Gardner wrote:
>>> Joel VanderWerf wrote:
>>>> Fixnum is not an instance of Fixnum. Compare:

>> ...
>>> Uh, I think you omitted the most important part of the documentation, to
>>> whit, what it actually says about Module#===:

>> http://blade.nagaokaut.ac.jp/cgi-bin...by-talk/336430

>
> Huh, odd. Bug in Ruby-forum, then, I guess. Sorry.
>
> ( http://www.ruby-forum.com/topic/186753#815590 )


Hm, it probably thought everything below the last hline was a sig.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Cisco 2611 and Cisco 1721 : Why , why , why ????? sam@nospam.org Cisco 10 05-01-2005 08:49 AM
Why, why, why??? =?Utf-8?B?VGltOjouLg==?= ASP .Net 6 01-27-2005 03:35 PM
Why Why Why You HAVE NO IDEA MCSE 31 04-24-2004 06:40 PM



Advertisments