From ec7c642f5fe60afc857aa64f1a9b4c2be56f9d70 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 26 Jan 2010 22:37:55 +0100 Subject: removes unused method Class#subclasses --- activesupport/lib/active_support/core_ext/class/removal.rb | 7 ------- activesupport/test/core_ext/class_test.rb | 10 ---------- 2 files changed, 17 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/class/removal.rb b/activesupport/lib/active_support/core_ext/class/removal.rb index 652be4ed78..82163eeb30 100644 --- a/activesupport/lib/active_support/core_ext/class/removal.rb +++ b/activesupport/lib/active_support/core_ext/class/removal.rb @@ -16,13 +16,6 @@ class Class #:nodoc: Object.remove_subclasses_of(self) end - # Returns an array with the names of the subclasses of +self+ as strings. - # - # Integer.subclasses # => ["Bignum", "Fixnum"] - def subclasses - Object.subclasses_of(self).map { |o| o.to_s } - end - # Removes the classes in +klasses+ from their parent module. # # Ordinary classes belong to some module via a constant. This method computes diff --git a/activesupport/test/core_ext/class_test.rb b/activesupport/test/core_ext/class_test.rb index bb4eb3c7d5..58b745a8b2 100644 --- a/activesupport/test/core_ext/class_test.rb +++ b/activesupport/test/core_ext/class_test.rb @@ -34,14 +34,4 @@ class ClassTest < Test::Unit::TestCase Class.remove_class(Y::Z::C) assert_raise(NameError) { Y::Z::C.is_a?(Class) } end - - def test_retrieving_subclasses - @parent = eval("class D; end; D") - @sub = eval("class E < D; end; E") - @subofsub = eval("class F < E; end; F") - assert_equal 2, @parent.subclasses.size - assert_equal [@subofsub.to_s], @sub.subclasses - assert_equal [], @subofsub.subclasses - assert_equal [@sub.to_s, @subofsub.to_s].sort, @parent.subclasses.sort - end end -- cgit v1.2.3 From 1b2ac25a2fe12d636f90bce1c510667d7accf407 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 26 Jan 2010 22:42:56 +0100 Subject: removes unused Class#remove_subclasses --- .../lib/active_support/core_ext/class/removal.rb | 9 --------- .../test/core_ext/object_and_class_ext_test.rb | 21 --------------------- 2 files changed, 30 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/class/removal.rb b/activesupport/lib/active_support/core_ext/class/removal.rb index 82163eeb30..c76c87e313 100644 --- a/activesupport/lib/active_support/core_ext/class/removal.rb +++ b/activesupport/lib/active_support/core_ext/class/removal.rb @@ -7,15 +7,6 @@ class Class #:nodoc: eval("defined?(::#{self}) && ::#{self}.equal?(self)") end - # Unassociates the class with its subclasses and removes the subclasses - # themselves. - # - # Integer.remove_subclasses # => [Bignum, Fixnum] - # Fixnum # => NameError: uninitialized constant Fixnum - def remove_subclasses - Object.remove_subclasses_of(self) - end - # Removes the classes in +klasses+ from their parent module. # # Ordinary classes belong to some module via a constant. This method computes diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb index e6fbdb637b..4305114f22 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -41,27 +41,6 @@ class Foo end class ClassExtTest < Test::Unit::TestCase - def test_methods - assert defined?(ClassB) - assert defined?(ClassC) - assert defined?(ClassD) - - ClassA.remove_subclasses - - assert !defined?(ClassB) - assert !defined?(ClassC) - assert !defined?(ClassD) - end - - def test_subclasses_of - cj = ClassJ - assert_equal [ClassJ], Object.subclasses_of(ClassI) - ClassI.remove_subclasses - assert_equal [], Object.subclasses_of(ClassI) - ensure - Object.const_set :ClassJ, cj - end - def test_subclasses_of_should_find_nested_classes assert Object.subclasses_of(ClassK).include?(Nested::ClassL) end -- cgit v1.2.3 From 5b01c8bb8bd9354fda8dc00c2df6888dbab7f017 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 26 Jan 2010 22:44:32 +0100 Subject: removes unused Object#remove_subclasses_of --- activesupport/lib/active_support/core_ext/object/extending.rb | 4 ---- 1 file changed, 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 b8b6970382..e1aed3fc3c 100644 --- a/activesupport/lib/active_support/core_ext/object/extending.rb +++ b/activesupport/lib/active_support/core_ext/object/extending.rb @@ -36,10 +36,6 @@ class Class end class Object - def remove_subclasses_of(*superclasses) #:nodoc: - Class.remove_class(*subclasses_of(*superclasses)) - end - # Exclude this class unless it's a subclass of our supers and is defined. # We check defined? in case we find a removed class that has yet to be # garbage collected. This also fails for anonymous classes -- please -- cgit v1.2.3 From 245bfafe335ff883f7a096eab95ac22fe2848679 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 26 Jan 2010 22:46:47 +0100 Subject: removes unused Object#subclasses_of --- .../active_support/core_ext/object/extending.rb | 12 ------ .../test/core_ext/object_and_class_ext_test.rb | 49 ---------------------- 2 files changed, 61 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/object/extending.rb b/activesupport/lib/active_support/core_ext/object/extending.rb index e1aed3fc3c..5a375f39ad 100644 --- a/activesupport/lib/active_support/core_ext/object/extending.rb +++ b/activesupport/lib/active_support/core_ext/object/extending.rb @@ -36,18 +36,6 @@ class Class end class Object - # Exclude this class unless it's a subclass of our supers and is defined. - # We check defined? in case we find a removed class that has yet to be - # garbage collected. This also fails for anonymous classes -- please - # submit a patch if you have a workaround. - def subclasses_of(*superclasses) #:nodoc: - subclasses = [] - superclasses.each do |klass| - subclasses.concat klass.descendents.select {|k| k.name.blank? || k.reachable?} - end - subclasses - end - def extended_by #:nodoc: ancestors = class << self; ancestors end ancestors.select { |mod| mod.class == Module } - [ Object, Kernel ] diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb index 4305114f22..375273d680 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -40,55 +40,6 @@ class Foo include Bar end -class ClassExtTest < Test::Unit::TestCase - def test_subclasses_of_should_find_nested_classes - assert Object.subclasses_of(ClassK).include?(Nested::ClassL) - end - - def test_subclasses_of_should_not_return_removed_classes - # First create the removed class - old_class = Nested.class_eval { remove_const :ClassL } - new_class = Class.new(ClassK) - Nested.const_set :ClassL, new_class - assert_equal "Nested::ClassL", new_class.name # Sanity check - - subclasses = Object.subclasses_of(ClassK) - assert subclasses.include?(new_class) - assert ! subclasses.include?(old_class) - ensure - Nested.const_set :ClassL, old_class unless defined?(Nested::ClassL) - end - - def test_subclasses_of_should_not_trigger_const_missing - const_missing = false - Nested.on_const_missing { const_missing = true } - - subclasses = Object.subclasses_of ClassK - assert !const_missing - assert_equal [ Nested::ClassL ], subclasses - - removed = Nested.class_eval { remove_const :ClassL } # keep it in memory - subclasses = Object.subclasses_of ClassK - assert !const_missing - assert subclasses.empty? - ensure - Nested.const_set :ClassL, removed unless defined?(Nested::ClassL) - end - - def test_subclasses_of_with_multiple_roots - classes = Object.subclasses_of(ClassI, ClassK) - assert_equal %w(ClassJ Nested::ClassL), classes.collect(&:to_s).sort - end - - def test_subclasses_of_doesnt_find_anonymous_classes - assert_equal [], Object.subclasses_of(Foo) - bar = Class.new(Foo) - assert_nothing_raised do - assert_equal [bar], Object.subclasses_of(Foo) - end - end -end - class ObjectTests < Test::Unit::TestCase def test_extended_by foo = Foo.new -- cgit v1.2.3 From f85f5dfc8ffefff174b695c6363211d342f77a57 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 26 Jan 2010 22:48:21 +0100 Subject: removes unused Class#descedents --- .../active_support/core_ext/object/extending.rb | 34 ---------------------- 1 file changed, 34 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/object/extending.rb b/activesupport/lib/active_support/core_ext/object/extending.rb index 5a375f39ad..76ed8801f9 100644 --- a/activesupport/lib/active_support/core_ext/object/extending.rb +++ b/activesupport/lib/active_support/core_ext/object/extending.rb @@ -1,40 +1,6 @@ require 'active_support/core_ext/class/removal' require 'active_support/core_ext/object/blank' -class Class - # Rubinius - if defined?(Class.__subclasses__) - def descendents - subclasses = [] - __subclasses__.each {|k| subclasses << k; subclasses.concat k.descendents } - subclasses - end - else - # MRI - begin - ObjectSpace.each_object(Class.new) {} - - def descendents - subclasses = [] - ObjectSpace.each_object(class << self; self; end) do |k| - subclasses << k unless k == self - end - subclasses - end - # JRuby - rescue StandardError - def descendents - subclasses = [] - ObjectSpace.each_object(Class) do |k| - subclasses << k if k < self - end - subclasses.uniq! - subclasses - end - end - end -end - class Object def extended_by #:nodoc: ancestors = class << self; ancestors end -- cgit v1.2.3 From 5f981ff0294ba45aa44ad15aa063970b29aeec44 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 26 Jan 2010 22:49:35 +0100 Subject: removes unused method Class#reachable? --- activesupport/lib/active_support/core_ext/class/removal.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/class/removal.rb b/activesupport/lib/active_support/core_ext/class/removal.rb index c76c87e313..80a920e4d6 100644 --- a/activesupport/lib/active_support/core_ext/class/removal.rb +++ b/activesupport/lib/active_support/core_ext/class/removal.rb @@ -2,11 +2,6 @@ require 'active_support/core_ext/object/extending' require 'active_support/core_ext/module/introspection' class Class #:nodoc: - - def reachable? - eval("defined?(::#{self}) && ::#{self}.equal?(self)") - end - # Removes the classes in +klasses+ from their parent module. # # Ordinary classes belong to some module via a constant. This method computes -- cgit v1.2.3 From 44afd785c8e390f47bc5b80e5d94309b6b56a13c Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 26 Jan 2010 22:51:44 +0100 Subject: removes unused method Class#remove_class --- .../lib/active_support/core_ext/class/removal.rb | 31 ---------------------- activesupport/test/core_ext/class_test.rb | 17 ------------ 2 files changed, 48 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/class/removal.rb b/activesupport/lib/active_support/core_ext/class/removal.rb index 80a920e4d6..74140eb978 100644 --- a/activesupport/lib/active_support/core_ext/class/removal.rb +++ b/activesupport/lib/active_support/core_ext/class/removal.rb @@ -2,35 +2,4 @@ require 'active_support/core_ext/object/extending' require 'active_support/core_ext/module/introspection' class Class #:nodoc: - # Removes the classes in +klasses+ from their parent module. - # - # Ordinary classes belong to some module via a constant. This method computes - # that constant name from the class name and removes it from the module it - # belongs to. - # - # Object.remove_class(Integer) # => [Integer] - # Integer # => NameError: uninitialized constant Integer - # - # Take into account that in general the class object could be still stored - # somewhere else. - # - # i = Integer # => Integer - # Object.remove_class(Integer) # => [Integer] - # Integer # => NameError: uninitialized constant Integer - # i.subclasses # => ["Bignum", "Fixnum"] - # Fixnum.superclass # => Integer - def remove_class(*klasses) - klasses.flatten.each do |klass| - # Skip this class if there is nothing bound to this name - next unless defined?(klass.name) - - basename = klass.to_s.split("::").last - parent = klass.parent - - # Skip this class if it does not match the current one bound to this name - next unless parent.const_defined?(basename) && klass = parent.const_get(basename) - - parent.instance_eval { remove_const basename } unless parent == klass - end - end end diff --git a/activesupport/test/core_ext/class_test.rb b/activesupport/test/core_ext/class_test.rb index 58b745a8b2..a082beb26a 100644 --- a/activesupport/test/core_ext/class_test.rb +++ b/activesupport/test/core_ext/class_test.rb @@ -17,21 +17,4 @@ module Y end class ClassTest < Test::Unit::TestCase - def test_removing_class_in_root_namespace - assert A.is_a?(Class) - Class.remove_class(A) - assert_raise(NameError) { A.is_a?(Class) } - end - - def test_removing_class_in_one_level_namespace - assert X::B.is_a?(Class) - Class.remove_class(X::B) - assert_raise(NameError) { X::B.is_a?(Class) } - end - - def test_removing_class_in_two_level_namespace - assert Y::Z::C.is_a?(Class) - Class.remove_class(Y::Z::C) - assert_raise(NameError) { Y::Z::C.is_a?(Class) } - end end -- cgit v1.2.3 From 7d312e54bad9c39634c137caec07dfc8df471650 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 26 Jan 2010 22:57:27 +0100 Subject: deletes no void files removal.rb and class_test.rb --- actionpack/test/abstract/layouts_test.rb | 1 - activesupport/lib/active_support/core_ext/class.rb | 1 - .../lib/active_support/core_ext/class/removal.rb | 5 ----- .../lib/active_support/core_ext/object/extending.rb | 1 - activesupport/test/core_ext/class_test.rb | 20 -------------------- .../test/core_ext/object_and_class_ext_test.rb | 1 - 6 files changed, 29 deletions(-) delete mode 100644 activesupport/lib/active_support/core_ext/class/removal.rb delete mode 100644 activesupport/test/core_ext/class_test.rb diff --git a/actionpack/test/abstract/layouts_test.rb b/actionpack/test/abstract/layouts_test.rb index df73d948f0..5c96d1cfff 100644 --- a/actionpack/test/abstract/layouts_test.rb +++ b/actionpack/test/abstract/layouts_test.rb @@ -1,5 +1,4 @@ require 'abstract_unit' -require 'active_support/core_ext/class/removal' module AbstractControllerTests module Layouts diff --git a/activesupport/lib/active_support/core_ext/class.rb b/activesupport/lib/active_support/core_ext/class.rb index 44ad6c8c08..62df7d8b82 100644 --- a/activesupport/lib/active_support/core_ext/class.rb +++ b/activesupport/lib/active_support/core_ext/class.rb @@ -1,4 +1,3 @@ require 'active_support/core_ext/class/attribute_accessors' require 'active_support/core_ext/class/inheritable_attributes' -require 'active_support/core_ext/class/removal' require 'active_support/core_ext/class/delegating_attributes' diff --git a/activesupport/lib/active_support/core_ext/class/removal.rb b/activesupport/lib/active_support/core_ext/class/removal.rb deleted file mode 100644 index 74140eb978..0000000000 --- a/activesupport/lib/active_support/core_ext/class/removal.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'active_support/core_ext/object/extending' -require 'active_support/core_ext/module/introspection' - -class Class #:nodoc: -end diff --git a/activesupport/lib/active_support/core_ext/object/extending.rb b/activesupport/lib/active_support/core_ext/object/extending.rb index 76ed8801f9..c3331ab478 100644 --- a/activesupport/lib/active_support/core_ext/object/extending.rb +++ b/activesupport/lib/active_support/core_ext/object/extending.rb @@ -1,4 +1,3 @@ -require 'active_support/core_ext/class/removal' require 'active_support/core_ext/object/blank' class Object diff --git a/activesupport/test/core_ext/class_test.rb b/activesupport/test/core_ext/class_test.rb deleted file mode 100644 index a082beb26a..0000000000 --- a/activesupport/test/core_ext/class_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'abstract_unit' -require 'active_support/core_ext/class' - -class A -end - -module X - class B - end -end - -module Y - module Z - class C - end - end -end - -class ClassTest < Test::Unit::TestCase -end diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb index 375273d680..33a321db36 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -1,7 +1,6 @@ require 'abstract_unit' require 'active_support/time' require 'active_support/core_ext/object' -require 'active_support/core_ext/class/removal' class ClassA; end class ClassB < ClassA; end -- cgit v1.2.3 From ccec730d7f2ccf5e44d3ac2b4b05c7c57af1cfb4 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 26 Jan 2010 23:01:51 +0100 Subject: removes unused method Object#extend_with_included_modules_from --- .../lib/active_support/core_ext/object/extending.rb | 4 ---- activesupport/test/core_ext/object_and_class_ext_test.rb | 15 --------------- 2 files changed, 19 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/object/extending.rb b/activesupport/lib/active_support/core_ext/object/extending.rb index c3331ab478..357ac4a18d 100644 --- a/activesupport/lib/active_support/core_ext/object/extending.rb +++ b/activesupport/lib/active_support/core_ext/object/extending.rb @@ -5,8 +5,4 @@ class Object ancestors = class << self; ancestors end ancestors.select { |mod| mod.class == Module } - [ Object, Kernel ] end - - def extend_with_included_modules_from(object) #:nodoc: - object.extended_by.each { |mod| extend mod } - end end diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb index 33a321db36..7046d0e3f4 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -47,21 +47,6 @@ class ObjectTests < Test::Unit::TestCase assert(([Bar, Baz] - foo.extended_by).empty?, "Expected Bar, Baz in #{foo.extended_by.inspect}") end - def test_extend_with_included_modules_from - foo, object = Foo.new, Object.new - assert !object.respond_to?(:bar) - assert !object.respond_to?(:baz) - - object.extend_with_included_modules_from(foo) - assert object.respond_to?(:bar) - assert !object.respond_to?(:baz) - - foo.extend(Baz) - object.extend_with_included_modules_from(foo) - assert object.respond_to?(:bar) - assert object.respond_to?(:baz) - end - class DuckTime def acts_like_time? true -- cgit v1.2.3 From c25ac0deeefe55837ba8fd2b2dc860924a507e63 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 26 Jan 2010 23:03:58 +0100 Subject: removes Object#extended_by --- activesupport/lib/active_support/core_ext/object/extending.rb | 4 ---- activesupport/test/core_ext/object_and_class_ext_test.rb | 7 ------- 2 files changed, 11 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/object/extending.rb b/activesupport/lib/active_support/core_ext/object/extending.rb index 357ac4a18d..ab446e399d 100644 --- a/activesupport/lib/active_support/core_ext/object/extending.rb +++ b/activesupport/lib/active_support/core_ext/object/extending.rb @@ -1,8 +1,4 @@ require 'active_support/core_ext/object/blank' class Object - def extended_by #:nodoc: - ancestors = class << self; ancestors end - ancestors.select { |mod| mod.class == Module } - [ Object, Kernel ] - end end diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb index 7046d0e3f4..0b2a9c418e 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -40,13 +40,6 @@ class Foo end class ObjectTests < Test::Unit::TestCase - def test_extended_by - foo = Foo.new - assert foo.extended_by.include?(Bar) - foo.extend(Baz) - assert(([Bar, Baz] - foo.extended_by).empty?, "Expected Bar, Baz in #{foo.extended_by.inspect}") - end - class DuckTime def acts_like_time? true -- cgit v1.2.3 From 3c6891593d84b83c70441b4c953080481bdcc4bf Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 26 Jan 2010 23:08:00 +0100 Subject: removes now void extending.rb --- actionpack/lib/action_view/helpers/prototype_helper.rb | 1 - activesupport/lib/active_support/core_ext/object.rb | 1 - activesupport/lib/active_support/core_ext/object/extending.rb | 4 ---- 3 files changed, 6 deletions(-) delete mode 100644 activesupport/lib/active_support/core_ext/object/extending.rb diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index ff7bc3b34e..bef93dd0f8 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -1,6 +1,5 @@ require 'set' require 'active_support/json' -require 'active_support/core_ext/object/extending' require 'active_support/core_ext/object/returning' module ActionView diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb index 04e8f06b3d..08e07a5b24 100644 --- a/activesupport/lib/active_support/core_ext/object.rb +++ b/activesupport/lib/active_support/core_ext/object.rb @@ -4,7 +4,6 @@ require 'active_support/core_ext/object/duplicable' require 'active_support/core_ext/object/try' require 'active_support/core_ext/object/conversions' -require 'active_support/core_ext/object/extending' require 'active_support/core_ext/object/instance_variables' require 'active_support/core_ext/object/metaclass' require 'active_support/core_ext/object/misc' diff --git a/activesupport/lib/active_support/core_ext/object/extending.rb b/activesupport/lib/active_support/core_ext/object/extending.rb deleted file mode 100644 index ab446e399d..0000000000 --- a/activesupport/lib/active_support/core_ext/object/extending.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'active_support/core_ext/object/blank' - -class Object -end -- cgit v1.2.3