Skip to content
This repository
Newer
Older
100644 78 lines (73 sloc) 1.949 kb
f28bd955 » jeremy
2009-04-22 Fix dependencies revealed by testing in isolation
1 require 'active_support/inflector'
2
dc0c9165 » jeremy
2009-03-28 Convert Module aliasing and introspection extension modules to class …
3 class Module
4 # Returns the name of the module containing this one.
5 #
81535d0f » fxn
2010-02-06 removes p calls in rdoc examples
6 # M::N.parent_name # => "M"
dc0c9165 » jeremy
2009-03-28 Convert Module aliasing and introspection extension modules to class …
7 def parent_name
92572241 » gazay
2012-04-29 AS core_ext refactoring pt.2
8 if defined? @parent_name
9 @parent_name
10 else
dc0c9165 » jeremy
2009-03-28 Convert Module aliasing and introspection extension modules to class …
11 @parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil
12 end
13 end
269c6c6b » jeremy
2008-07-09 Cache Module#parent_name
14
dc0c9165 » jeremy
2009-03-28 Convert Module aliasing and introspection extension modules to class …
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 #
81535d0f » fxn
2010-02-06 removes p calls in rdoc examples
23 # M::N.parent # => M
24 # X.parent # => M
dc0c9165 » jeremy
2009-03-28 Convert Module aliasing and introspection extension modules to class …
25 #
26 # The parent of top-level and anonymous modules is Object.
27 #
81535d0f » fxn
2010-02-06 removes p calls in rdoc examples
28 # M.parent # => Object
29 # Module.new.parent # => Object
dc0c9165 » jeremy
2009-03-28 Convert Module aliasing and introspection extension modules to class …
30 def parent
f28bd955 » jeremy
2009-04-22 Fix dependencies revealed by testing in isolation
31 parent_name ? ActiveSupport::Inflector.constantize(parent_name) : Object
dc0c9165 » jeremy
2009-03-28 Convert Module aliasing and introspection extension modules to class …
32 end
dc604b43 » jeremy
2008-01-04 Ruby 1.9: Module#local_constants can now just use constants(false). C…
33
dc0c9165 » jeremy
2009-03-28 Convert Module aliasing and introspection extension modules to class …
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 #
81535d0f » fxn
2010-02-06 removes p calls in rdoc examples
43 # M.parents # => [Object]
44 # M::N.parents # => [M, Object]
45 # X.parents # => [M, Object]
dc0c9165 » jeremy
2009-03-28 Convert Module aliasing and introspection extension modules to class …
46 def parents
47 parents = []
48 if parent_name
49 parts = parent_name.split('::')
50 until parts.empty?
f28bd955 » jeremy
2009-04-22 Fix dependencies revealed by testing in isolation
51 parents << ActiveSupport::Inflector.constantize(parts * '::')
dc0c9165 » jeremy
2009-03-28 Convert Module aliasing and introspection extension modules to class …
52 parts.pop
269c6c6b » jeremy
2008-07-09 Cache Module#parent_name
53 end
dc0c9165 » jeremy
2009-03-28 Convert Module aliasing and introspection extension modules to class …
54 end
55 parents << Object unless parents.include? Object
56 parents
57 end
dc604b43 » jeremy
2008-01-04 Ruby 1.9: Module#local_constants can now just use constants(false). C…
58
7ab47751 » josevalim
2011-12-20 Initial pass at removing dead 1.8.x code from Active Support.
59 def local_constants #:nodoc:
60 constants(false)
dc0c9165 » jeremy
2009-03-28 Convert Module aliasing and introspection extension modules to class …
61 end
62
04df7bb0 » fxn
2012-01-12 deprecates Module#local_constant_names
63 # *DEPRECATED*: Use +local_constants+ instead.
64 #
65 # Returns the names of the constants defined locally as strings.
66 #
67 # module M
68 # X = 1
69 # end
70 # M.local_constant_names # => ["X"]
71 #
72 # This method is useful for forward compatibility, since Ruby 1.8 returns
73 # constant names as strings, whereas 1.9 returns them as symbols.
dc0c9165 » jeremy
2009-03-28 Convert Module aliasing and introspection extension modules to class …
74 def local_constant_names
b955939d » gazay
2012-10-30 Make caller attribute in deprecation methods optional
75 ActiveSupport::Deprecation.warn 'Module#local_constant_names is deprecated, use Module#local_constants instead'
dc0c9165 » jeremy
2009-03-28 Convert Module aliasing and introspection extension modules to class …
76 local_constants.map { |c| c.to_s }
c64a29f6 » jeremy
2007-12-22 Ruby 1.9 compat: dependencies uses Module#local_constant_names. Refer…
77 end
9efca539 » seckar
2006-03-27 Dependencies cleanup. Fixes #4221.
78 end
Something went wrong with that request. Please try again.