Skip to content

Latest commit

 

History

History
28 lines (23 loc) · 538 Bytes

demodulize-a-class-name.md

File metadata and controls

28 lines (23 loc) · 538 Bytes

Demodulize A Class Name

If you call .class.name on an instance of some class, the fully qualified name will be returned, module names and all. Consider the following example class:

module One
  module Two
    class Three
      ...
    end
  end
end
> One::Two::Three.new.class.name
#=> "One::Two::Three"

If you just want the unqualified class name; modules not included, you can use the #demodulize method provided by ActiveSupport.

> One::Two::Three.new.class.name.demodulize
#=> "Three"