I don't think there is anything to handle this in the main / standard library.
As an alternative to custom writing methods, there is always activesupport:
require 'active_support/core_ext/string/inflections'
Cowsay::Character::Stegosaurus.name.demodulize
Cowsay::Character::Stegosaurus.name.deconstantize
These methods are implemented as follows:
def demodulize(path)
path = path.to_s
if i = path.rindex('::')
path[(i+2)..-1]
else
path
end
end
def deconstantize(path)
path.to_s[0, path.rindex('::') || 0]
end
Check out the docs if you are interested in other methods.
Concerning
A From A::B::C
require activesupport, Module, parent
require 'active_support'
Cowsay::Character::Stegosaurus.parent
, activesupport , .