# Re: Better ruby way for caseing on class?

**URL:** <https://www.ruby-forum.com/t/re-better-ruby-way-for-caseing-on-class/71021>\
**Category:** Ruby\
**Created:** [October 4, 2006, 6:28pm UTC](https://www.ruby-forum.com/t/re-better-ruby-way-for-caseing-on-class/71021 "2006-10-04T18:28:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [October 4, 2006, 6:28pm UTC](https://www.ruby-forum.com/t/re-better-ruby-way-for-caseing-on-class/71021/1 "2006-10-04T18:28:55Z")

</div>

From: James Edward G. II [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

> Sure. Drop the call to to\_s() and the ’ … 's around the class  
> names. Case calls ===() for the condition object and Class defines  
> ===() to do what you expect here.

Er…not quite, because (in his example) he has class objects, not  
instances.

[Kernel,String,Object].each do |klass|  
case klass  
when Kernel  
puts “I’m doing stuff with object Kernel”  
when String  
puts “I’m doing stuff with object String”  
when Object  
puts “I’m doing stuff with object Object”  
end  
end  
#=\> I’m doing stuff with object Kernel  
#=\> I’m doing stuff with object Kernel  
#=\> I’m doing stuff with object Kernel

ebeard, in reality are you trying to handle class objects in your case  
statement, or do you have instances of that class that you’re trying to  
determine the class of?

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [October 4, 2006, 6:32pm UTC](https://www.ruby-forum.com/t/re-better-ruby-way-for-caseing-on-class/71021/2 "2006-10-04T18:32:55Z")

</div>

On Oct 4, 2006, at 11:27 AM, Gavin K. wrote:

> From: James Edward G. II [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]
> 
> > Sure. Drop the call to to\_s() and the ’ … 's around the class  
> > names. Case calls ===() for the condition object and Class defines  
> > ===() to do what you expect here.
> 
> Er…not quite, because (in his example) he has class objects, not  
> instances.

Egad, very good point. I apologize.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [October 5, 2006, 8:39pm UTC](https://www.ruby-forum.com/t/re-better-ruby-way-for-caseing-on-class/71021/3 "2006-10-05T20:39:29Z")

</div>

I’m actually dealing with classes. not instances thereof.
