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'
Written by Lucas
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#