Last Updated: September 29, 2021
·
1.089K
· lucasdavila

demodulize method

On ruby on rails you can remove the module part from a constant expression with the '.demodulize' method, eg:

'FooNamespace::FooBar'.demodulize
> 'FooBar'

You can use this method on ruby too, by requiring the 'ActiveSupport::CoreExtensions::String::Inflections' module, eg:

require 'active_support/core_ext/string/inflections'

'FooNamespace::FooBar'.demodulize
> 'FooBar'