Changeset 7590
- Timestamp:
- 09/23/07 01:09:20 (10 months ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/object/extending.rb (modified) (1 diff)
- trunk/activesupport/test/abstract_unit.rb (modified) (1 diff)
- trunk/activesupport/test/core_ext/object_and_class_ext_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r7569 r7590 1 1 *SVN* 2 3 * Object.subclasses_of includes anonymous subclasses. [Jeremy Kemper] 2 4 3 5 * Fixed that pluralizing an empty string should return the same empty string, not "s" #7720 [josh] trunk/activesupport/lib/active_support/core_ext/object/extending.rb
r6443 r7590 6 6 def subclasses_of(*superclasses) #:nodoc: 7 7 subclasses = [] 8 9 # Exclude this class unless it's a subclass of our supers and is defined. 10 # We check defined? in case we find a removed class that has yet to be 11 # garbage collected. This also fails for anonymous classes -- please 12 # submit a patch if you have a workaround. 8 13 ObjectSpace.each_object(Class) do |k| 9 next unless # Exclude this class unless 10 superclasses.any? { |superclass| k < superclass } && # It *is* a subclass of our supers 11 eval("defined?(::#{k}) && ::#{k}.object_id == k.object_id") # It *is* defined 12 # Note that we check defined? in case we find a removed class that has 13 # yet to be garbage collected. 14 subclasses << k 14 if superclasses.any? { |superclass| k < superclass } && 15 (k.name.blank? || eval("defined?(::#{k}) && ::#{k}.object_id == k.object_id")) 16 subclasses << k 17 end 15 18 end 19 16 20 subclasses 17 21 end 18 22 19 23 def extended_by #:nodoc: 20 24 ancestors = class << self; ancestors end trunk/activesupport/test/abstract_unit.rb
r7486 r7590 7 7 def uses_mocha(test_name) 8 8 require 'rubygems' 9 gem 'mocha', '>= 0.5.5' 9 10 require 'mocha' 10 11 yield trunk/activesupport/test/core_ext/object_and_class_ext_test.rb
r6036 r7590 98 98 assert_equal %w(ClassJ Nested::ClassL), classes.collect(&:to_s).sort 99 99 end 100 100 101 def test_subclasses_of_doesnt_find_anonymous_classes 102 assert_equal [], Object.subclasses_of(Foo) 103 bar = Class.new(Foo) 104 assert_nothing_raised do 105 assert_equal [bar], Object.subclasses_of(Foo) 106 end 107 end 101 108 end 102 109