Method: Module.dirname

Defined in:
lib/quality_extensions/module/namespace.rb

.dirname(module_or_name) ⇒ Object Also known as: namespace_name_of

Gets the “dirname” of a “module path” (the string/symbol representing the namespace modules that it is contained in), in the same sense that File.dirname returns the dirname of a filesystem path.

Same as namespace_of, only this just returns the name of the namespace module (as a string), rather than returning the constant itself.

See also Module.basename



31
32
33
34
35
36
37
38
39
40
# File 'lib/quality_extensions/module/namespace.rb', line 31

def self.dirname(module_or_name)
  case module_or_name
    when Module
      module_or_name.namespace_module.name
    when Symbol
      Module.split_name(module_or_name)[0..-2].join('::')
    when String
      Module.split_name(module_or_name)[0..-2].join('::')
  end
end