class Module

def parents

X.parents # => [M, Object]
M::N.parents # => [M, Object]
M.parents # => [Object]

X = M::N
end
end
module N
module M

nested outwards. The receiver is not contained within the result.
Returns all the parents of this module according to its name, ordered from
def parents
  parents = []
  if parent_name
    parts = parent_name.split('::')
    until parts.empty?
      parents << ActiveSupport::Inflector.constantize(parts * '::')
      parts.pop
    end
  end
  parents << Object unless parents.include? Object
  parents
end