Skip to content
Tags

case statement for class

October 9, 2011

So the most intuitive way of writing a case statement that checks for class does not work:

This does not work:

def try_this record

case record.class

when BlogEntry

puts "it is"

else

puts "it is not"

end

end

this works:

 

def try_this record

case record

when BlogEntry

puts "it is"

else

puts "it is not"

end

end

I was helped by this blog entry http://www.postal-code.com/mrhappy/blog/2007/02/01/ruby-comparing-an-objects-class-in-a-case-statement/

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: