# What on earth

**URL:** <https://www.ruby-forum.com/t/what-on-earth/85729>\
**Category:** Ruby\
**Created:** [March 23, 2006, 3:51am UTC](https://www.ruby-forum.com/t/what-on-earth/85729 "2006-03-23T03:51:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [March 23, 2006, 3:51am UTC](https://www.ruby-forum.com/t/what-on-earth/85729/1 "2006-03-23T03:51:30Z")

</div>

a = 5  
puts Fixnum == a.class # spits out true

# spits out “Who knows what I am. :-(”

case a.class  
when Fixnum  
puts “I’m a fixnum!”  
else  
puts “Who knows what I am. :-(”  
end

What’s going on here?

Joe

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [March 23, 2006, 3:59am UTC](https://www.ruby-forum.com/t/what-on-earth/85729/2 "2006-03-23T03:59:27Z")

</div>

case uses === for comparison, not ==

In my irb, Fixnum === 5.class =\> false

As for why === gives false, I have no idea. In the mean time, you  
could use

case a.class.to\_s  
when “Fixnum”  
puts …  
else  
puts …  
end

Tim

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [March 23, 2006, 4:00am UTC](https://www.ruby-forum.com/t/what-on-earth/85729/3 "2006-03-23T04:00:06Z")

</div>

On 22-Mar-06, at 9:51 PM, Joe Van D. wrote:

> What’s going on here?

case doesn’t use == you can do this:

a = 5

case a  
when Fixnum  
puts “I’m a fixnum”  
else  
puts “other”  
end

and by coincidence (not)

ratdog:~/tmp mike$ irb  
irb(main):001:0\> a = 5  
=\> 5  
irb(main):002:0\> Fixnum === a  
=\> true

## ratdog:~/tmp mike$ ri 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.

```

Hope this helps,

Mike

–

Mike S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.stok.ca/~mike/](http://www.stok.ca/~mike/)

The “`Stok’ disclaimers” apply.

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [March 23, 2006, 4:08am UTC](https://www.ruby-forum.com/t/what-on-earth/85729/4 "2006-03-23T04:08:29Z")

</div>

> class.

Ok, out of the three of us that responded, Mike is the one who knows  
what he’s talking about most. Listen to him.

Tim

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [March 23, 2006, 4:27am UTC](https://www.ruby-forum.com/t/what-on-earth/85729/5 "2006-03-23T04:27:15Z")

</div>

On 3/22/06, Mike S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > else  
> > case a  
> > when Fixnum  
> > puts “I’m a fixnum”  
> > else  
> > puts “other”  
> > end

Very nice, thanks! Less code is always better.
