# Re: Better ruby way for caseing on class?

**URL:** <https://www.ruby-forum.com/t/re-better-ruby-way-for-caseing-on-class/71020>\
**Category:** Ruby\
**Created:** [October 4, 2006, 6:36pm UTC](https://www.ruby-forum.com/t/re-better-ruby-way-for-caseing-on-class/71020 "2006-10-04T18:36:57Z")\
**Posts on this page:** 2\
**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:36pm UTC](https://www.ruby-forum.com/t/re-better-ruby-way-for-caseing-on-class/71020/1 "2006-10-04T18:36:57Z")

</div>

From: ebeard [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

> Is there a better way?

Here’s one option:

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

---

<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:41pm UTC](https://www.ruby-forum.com/t/re-better-ruby-way-for-caseing-on-class/71020/2 "2006-10-05T20:41:29Z")

</div>

yep that will work and looks like a reasonable alternative.
