Sha256: 1b36b47f53a14de8f1fd34c00f3d8a53c8a4b6a86d17a0fa311206daf50156ca

Contents?: true

Size: 1.62 KB

Versions: 29

Compression:

Stored size: 1.62 KB

Contents

require 'active_support/inflector'

class Module
  # Returns the name of the module containing this one.
  #
  #   M::N.parent_name # => "M"
  def parent_name
    if defined?(@parent_name)
      @parent_name
    else
      parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil
      @parent_name = parent_name unless frozen?
      parent_name
    end
  end

  # Returns the module which contains this one according to its name.
  #
  #   module M
  #     module N
  #     end
  #   end
  #   X = M::N
  #
  #   M::N.parent # => M
  #   X.parent    # => M
  #
  # The parent of top-level and anonymous modules is Object.
  #
  #   M.parent          # => Object
  #   Module.new.parent # => Object
  def parent
    parent_name ? ActiveSupport::Inflector.constantize(parent_name) : Object
  end

  # Returns all the parents of this module according to its name, ordered from
  # nested outwards. The receiver is not contained within the result.
  #
  #   module M
  #     module N
  #     end
  #   end
  #   X = M::N
  #
  #   M.parents    # => [Object]
  #   M::N.parents # => [M, Object]
  #   X.parents    # => [M, Object]
  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

  def local_constants #:nodoc:
    ActiveSupport::Deprecation.warn(<<-MSG.squish)
      Module#local_constants is deprecated and will be removed in Rails 5.1.
      Use Module#constants(false) instead.
    MSG
    constants(false)
  end
end

Version data entries

29 entries across 28 versions & 5 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.0.7.1/lib/active_support/core_ext/module/introspection.rb
activesupport-5.0.7.2 lib/active_support/core_ext/module/introspection.rb
activesupport-5.0.7.1 lib/active_support/core_ext/module/introspection.rb
activesupport-5.0.7 lib/active_support/core_ext/module/introspection.rb
activesupport-5.0.6 lib/active_support/core_ext/module/introspection.rb
activesupport-5.0.6.rc1 lib/active_support/core_ext/module/introspection.rb
activesupport-5.0.5 lib/active_support/core_ext/module/introspection.rb
activesupport-5.0.5.rc2 lib/active_support/core_ext/module/introspection.rb
activesupport-5.0.5.rc1 lib/active_support/core_ext/module/introspection.rb
tdiary-5.0.5 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/module/introspection.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/module/introspection.rb
activesupport-5.0.4 lib/active_support/core_ext/module/introspection.rb
activesupport-5.0.4.rc1 lib/active_support/core_ext/module/introspection.rb
activesupport-5.0.3 lib/active_support/core_ext/module/introspection.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activesupport-5.0.2/lib/active_support/core_ext/module/introspection.rb
lazy_record-0.2.1 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/module/introspection.rb
lazy_record-0.2.0 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/module/introspection.rb
lazy_record-0.1.9 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/module/introspection.rb
lazy_record-0.1.8 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/module/introspection.rb
lazy_record-0.1.7 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/core_ext/module/introspection.rb