Skip to content
Newer
Older
100644 67 lines (62 sloc) 1.55 KB
f28bd95 @jeremy Fix dependencies revealed by testing in isolation
jeremy authored Apr 22, 2009
1 require 'active_support/inflector'
2
dc0c916 @jeremy Convert Module aliasing and introspection extension modules to class …
jeremy authored Mar 28, 2009
3 class Module
4 # Returns the name of the module containing this one.
5 #
81535d0 @fxn removes p calls in rdoc examples
fxn authored Feb 6, 2010
6 # M::N.parent_name # => "M"
dc0c916 @jeremy Convert Module aliasing and introspection extension modules to class …
jeremy authored Mar 29, 2009
7 def parent_name
9257224 @gazay AS core_ext refactoring pt.2
gazay authored Apr 29, 2012
8 if defined? @parent_name
9 @parent_name
10 else
dc0c916 @jeremy Convert Module aliasing and introspection extension modules to class …
jeremy authored Mar 29, 2009
11 @parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil
12 end
13 end
269c6c6 @jeremy Cache Module#parent_name
jeremy authored Jul 9, 2008
14
dc0c916 @jeremy Convert Module aliasing and introspection extension modules to class …
jeremy authored Mar 29, 2009
15 # Returns the module which contains this one according to its name.
16 #
17 # module M
18 # module N
19 # end
20 # end
21 # X = M::N
22 #
81535d0 @fxn removes p calls in rdoc examples
fxn authored Feb 6, 2010
23 # M::N.parent # => M
24 # X.parent # => M
dc0c916 @jeremy Convert Module aliasing and introspection extension modules to class …
jeremy authored Mar 29, 2009
25 #
26 # The parent of top-level and anonymous modules is Object.
27 #
81535d0 @fxn removes p calls in rdoc examples
fxn authored Feb 6, 2010
28 # M.parent # => Object
29 # Module.new.parent # => Object
dc0c916 @jeremy Convert Module aliasing and introspection extension modules to class …
jeremy authored Mar 29, 2009
30 def parent
f28bd95 @jeremy Fix dependencies revealed by testing in isolation
jeremy authored Apr 23, 2009
31 parent_name ? ActiveSupport::Inflector.constantize(parent_name) : Object
dc0c916 @jeremy Convert Module aliasing and introspection extension modules to class …
jeremy authored Mar 29, 2009
32 end
dc604b4 @jeremy Ruby 1.9: Module#local_constants can now just use constants(false). C…
jeremy authored Jan 4, 2008
33
dc0c916 @jeremy Convert Module aliasing and introspection extension modules to class …
jeremy authored Mar 29, 2009
34 # Returns all the parents of this module according to its name, ordered from
35 # nested outwards. The receiver is not contained within the result.
36 #
37 # module M
38 # module N
39 # end
40 # end
41 # X = M::N
42 #
81535d0 @fxn removes p calls in rdoc examples
fxn authored Feb 6, 2010
43 # M.parents # => [Object]
44 # M::N.parents # => [M, Object]
45 # X.parents # => [M, Object]
dc0c916 @jeremy Convert Module aliasing and introspection extension modules to class …
jeremy authored Mar 29, 2009
46 def parents
47 parents = []
48 if parent_name
49 parts = parent_name.split('::')
50 until parts.empty?
f28bd95 @jeremy Fix dependencies revealed by testing in isolation
jeremy authored Apr 23, 2009
51 parents << ActiveSupport::Inflector.constantize(parts * '::')
dc0c916 @jeremy Convert Module aliasing and introspection extension modules to class …
jeremy authored Mar 29, 2009
52 parts.pop
269c6c6 @jeremy Cache Module#parent_name
jeremy authored Jul 10, 2008
53 end
dc0c916 @jeremy Convert Module aliasing and introspection extension modules to class …
jeremy authored Mar 29, 2009
54 end
55 parents << Object unless parents.include? Object
56 parents
57 end
dc604b4 @jeremy Ruby 1.9: Module#local_constants can now just use constants(false). C…
jeremy authored Jan 4, 2008
58
7ab4775 @josevalim Initial pass at removing dead 1.8.x code from Active Support.
josevalim authored Dec 20, 2011
59 def local_constants #:nodoc:
86d4e18 @yui-knk Deprecate `Module.local_constants`
yui-knk authored Feb 28, 2016
60 ActiveSupport::Deprecation.warn(<<-MSG.squish)
61 Module#local_constants is deprecated and will be removed in Rails 5.1.
62 Use Module#constants(false) instead.
63 MSG
7ab4775 @josevalim Initial pass at removing dead 1.8.x code from Active Support.
josevalim authored Dec 20, 2011
64 constants(false)
dc0c916 @jeremy Convert Module aliasing and introspection extension modules to class …
jeremy authored Mar 29, 2009
65 end
9efca53 @seckar Dependencies cleanup. Fixes #4221.
seckar authored Mar 27, 2006
66 end
Something went wrong with that request. Please try again.