Skip to content

Commit

Permalink
removes unused method Class#remove_class
Browse files Browse the repository at this point in the history
  • Loading branch information
fxn committed Jan 26, 2010
1 parent 5f981ff commit 44afd78
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 48 deletions.
31 changes: 0 additions & 31 deletions activesupport/lib/active_support/core_ext/class/removal.rb
Expand Up @@ -2,35 +2,4 @@
require 'active_support/core_ext/module/introspection' require 'active_support/core_ext/module/introspection'


class Class #:nodoc: 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 end
17 changes: 0 additions & 17 deletions activesupport/test/core_ext/class_test.rb
Expand Up @@ -17,21 +17,4 @@ class C
end end


class ClassTest < Test::Unit::TestCase 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 end

0 comments on commit 44afd78

Please sign in to comment.