diff options
author | Nicholas Seckar <nseckar@gmail.com> | 2006-03-26 20:00:40 +0000 |
---|---|---|
committer | Nicholas Seckar <nseckar@gmail.com> | 2006-03-26 20:00:40 +0000 |
commit | 3bab575316d919d1d51b9384f76f73cbcb0971e9 (patch) | |
tree | 0554cb4f20fbf4c650d6148b941e4217ce840fa9 /activesupport/lib | |
parent | 4238666627a6b319c19f22ee279d15284ed5f245 (diff) | |
download | rails-3bab575316d919d1d51b9384f76f73cbcb0971e9.tar.gz rails-3bab575316d919d1d51b9384f76f73cbcb0971e9.tar.bz2 rails-3bab575316d919d1d51b9384f76f73cbcb0971e9.zip |
Update Object.subclasses_of to locate nested classes. Update Object.remove_subclasses_of to use Class.remove_class.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4049 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/extending.rb | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/extending.rb b/activesupport/lib/active_support/core_ext/object/extending.rb index 9abdfc0bc9..16f62d85b7 100644 --- a/activesupport/lib/active_support/core_ext/object/extending.rb +++ b/activesupport/lib/active_support/core_ext/object/extending.rb @@ -1,14 +1,17 @@ class Object #:nodoc: def remove_subclasses_of(*superclasses) - subclasses_of(*superclasses).each do |subclass| - Object.send(:remove_const, subclass.to_s) rescue nil - end + Class.remove_class(*subclasses_of(*superclasses)) end def subclasses_of(*superclasses) subclasses = [] ObjectSpace.each_object(Class) do |k| - next if (k.ancestors & superclasses).empty? || superclasses.include?(k) || k.to_s.include?("::") || subclasses.include?(k) || !Object.const_defined?(k.to_s.to_sym) + next if # Exclude this class if + (k.ancestors & superclasses).empty? || # It's not a subclass of our supers + superclasses.include?(k) || # It *is* one of the supers + subclasses.include?(k) || # We already have it for some obscure reason + eval("! defined?(::#{k})") || # It's not defined. + eval("::#{k}").object_id != k.object_id subclasses << k end subclasses |