How do I get the name of a Ruby class? How do I get the name of a Ruby class? ruby ruby

How do I get the name of a Ruby class?


You want to call .name on the object's class:

result.class.name


Here's the correct answer, extracted from comments by Daniel Rikowski and pseidemann. I'm tired of having to weed through comments to find the right answer...

If you use Rails (ActiveSupport):

result.class.name.demodulize

If you use POR (plain-ol-Ruby):

result.class.name.split('::').last


Both result.class.to_s and result.class.name work.