#--
# Special thanks to Mauricio Fernandez
#   parent = Object.const_get(mod.to_s.sub(/::[^:]+\z/, ""))
#++

class Module

  def nesting
    n = []
    name.split(/::/).inject(self){ |mod, name| c = mod.const_get(name) ; n << c ; c }
    return n
  end

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCModule < Test::Unit::TestCase

    module M
      module N
        class C
          def n
            self.class.nesting
          end
        end
      end
    end

    def test_nesting
      assert_equal( [TCModule, M, M::N, M::N::C], M::N::C.new.n )
    end

  end

=end
