Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/ae_page_objects/core_ext/module.rb

Overview

lifted from activesupport

Instance Method Summary collapse

Instance Method Details

#parentObject

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


31
32
33
# File 'lib/ae_page_objects/core_ext/module.rb', line 31

def parent
  parent_name ? AePageObjects::Inflector.constantize(parent_name) : Object
end

#parent_nameObject

Returns the name of the module containing this one.

M::N.parent_name # => "M"


8
9
10
11
12
13
# File 'lib/ae_page_objects/core_ext/module.rb', line 8

def parent_name
  unless defined? @parent_name
    @parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil
  end
  @parent_name
end