Method: Module#enclosures

Defined in:
lib/core/facets/module/enclosure.rb

#enclosuresObject

Returns all the namespaces of this module according ordered from nearest and moving outwards. The receiver is not contained within the result.

module ::EncExample
  module M
    module N
    end
  end
end

EncExample.enclosures        #=> [Object]
EncExample::M.enclosures     #=> [EncExample, Object]
EncExample::M::N.enclosures  #=> [EncExample::M, EncExample, Object]

NOTE: This method is not a common core extension and is not loaded automatically when using require 'facets'.

Uncommon:

  • require ‘facets/module/enclosures’



63
64
65
66
67
68
69
70
71
# File 'lib/core/facets/module/enclosure.rb', line 63

def enclosures
  n = []
  name.split(/::/).inject(self) do |mod, cref|
    c = mod.const_get(cref) ; n.unshift(c) ; c
  end
  n << Object # ?
  n.shift # we really don't need +self+ too.
  n
end