Changeset 6426
- Timestamp:
- 03/14/07 23:27:28 (2 years ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/module/introspection.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/dependencies.rb (modified) (3 diffs)
- trunk/activesupport/test/core_ext/module_test.rb (modified) (2 diffs)
- trunk/activesupport/test/dependencies_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r6378 r6426 1 1 *SVN* 2 3 * Update Dependencies to ignore constants inherited from ancestors. Closes #6951. [Nicholas Seckar] 2 4 3 5 * Array#to_query preserves its ordering. #7756 [Greg Spurrier] trunk/activesupport/lib/active_support/core_ext/module/introspection.rb
r4060 r6426 19 19 parents 20 20 end 21 22 # Return the constants that have been defined locally by this object and not 23 # in an ancestor. This method may miss some constants if their definition in 24 # the ancestor is identical to their definition in the receiver. 25 def local_constants 26 inherited = {} 27 ancestors.each do |anc| 28 next if anc == self 29 anc.constants.each { |const| inherited[const] = anc.const_get(const) } 30 end 31 constants.select do |const| 32 ! inherited.key?(const) || inherited[const].object_id != const_get(const).object_id 33 end 34 end 21 35 end trunk/activesupport/lib/active_support/dependencies.rb
r6083 r6426 319 319 if desc.is_a? Module 320 320 mod_name = desc.name 321 initial_constants = desc. constants321 initial_constants = desc.local_constants 322 322 elsif desc.is_a?(String) || desc.is_a?(Symbol) 323 323 mod_name = desc.to_s … … 325 325 # Handle the case where the module has yet to be defined. 326 326 initial_constants = if qualified_const_defined?(mod_name) 327 mod_name.constantize. constants327 mod_name.constantize.local_constants 328 328 else 329 329 [] … … 350 350 mod = mod_name.constantize 351 351 next [] unless mod.is_a? Module 352 new_constants = mod. constants - prior_constants352 new_constants = mod.local_constants - prior_constants 353 353 354 354 # Make sure no other frames takes credit for these constants. trunk/activesupport/test/core_ext/module_test.rb
r5113 r6426 2 2 3 3 module One 4 Constant1 = "Hello World" 5 Constant2 = "What's up?" 4 6 end 5 7 6 8 class Ab 7 9 include One 10 Constant1 = "Hello World" # Will have different object id than One::Constant1 11 Constant3 = "Goodbye World" 8 12 end 9 13 … … 91 95 assert_equal [Yz::Zy, Yz, Object], Yz::Zy::Cd.parents 92 96 assert_equal [Yz, Object], Yz::Zy.parents 97 end 98 99 def test_local_constants 100 assert_equal %w(Constant1 Constant3), Ab.local_constants.sort 93 101 end 94 102 trunk/activesupport/test/dependencies_test.rb
r5816 r6426 8 8 name 9 9 end 10 end 11 12 module ModuleWithConstant 13 InheritedConstant = "Hello" 10 14 end 11 15 … … 573 577 ensure 574 578 Object.send :remove_const, :M rescue nil 579 end 580 581 def test_new_constants_in_with_inherited_constants 582 m = Dependencies.new_constants_in(:Object) do 583 Object.send :include, ModuleWithConstant 584 end 585 assert_equal [], m 575 586 end 576 587