aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/module/introspection.rb
diff options
context:
space:
mode:
authorNicholas Seckar <nseckar@gmail.com>2006-03-27 05:13:46 +0000
committerNicholas Seckar <nseckar@gmail.com>2006-03-27 05:13:46 +0000
commit9efca53908c09b7f188183aec6c0a4a2df347316 (patch)
treebd1eacf10bdcaef1112bf0c36d3a3743fb092733 /activesupport/lib/active_support/core_ext/module/introspection.rb
parent24403498ba8582d29f55aab16ffd5920dec1c669 (diff)
downloadrails-9efca53908c09b7f188183aec6c0a4a2df347316.tar.gz
rails-9efca53908c09b7f188183aec6c0a4a2df347316.tar.bz2
rails-9efca53908c09b7f188183aec6c0a4a2df347316.zip
Dependencies cleanup. Fixes #4221.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4060 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext/module/introspection.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/module/introspection.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/introspection.rb b/activesupport/lib/active_support/core_ext/module/introspection.rb
new file mode 100644
index 0000000000..0cd0d1ff2c
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/module/introspection.rb
@@ -0,0 +1,21 @@
+class Module
+ # Return the module which contains this one; if this is a root module, such as
+ # +::MyModule+, then Object is returned.
+ def parent
+ parent_name = name.split('::')[0..-2] * '::'
+ parent_name.empty? ? Object : parent_name.constantize
+ end
+
+ # Return all the parents of this module, ordered from nested outwards. The
+ # receiver is not contained within the result.
+ def parents
+ parents = []
+ parts = name.split('::')[0..-2]
+ until parts.empty?
+ parents << (parts * '::').constantize
+ parts.pop
+ end
+ parents << Object unless parents.include? Object
+ parents
+ end
+end