Asked • 03/18/19

How do I get the name of a Ruby class?

How can I get the class name from an ActiveRecord object?I have: result = User.find(1)I tried: result.class # => User(id: integer, name: string ...) result.to_s # => #<0x3d07cdc>"I need only the class name, in a string (`User` in this case). Is there a method for that? I know this is pretty basic, but I searched both Rails' and Ruby's docs, and I couldn't find it.0x3d07cdc>

1 Expert Answer


Wyatt G. answered • 12/24/20

New to Wyzant

Software Engineer and Architect Specializing in Ruby on Rails

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.


Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.