Sha256: 0499ca7fa97d553e87ddccb396e92d31f57e6fa27b67d2c2535754d8aa3a9891

Contents?: true

Size: 796 Bytes

Versions: 22

Compression:

Stored size: 796 Bytes

Contents

#--
# Original code from RubyOnRails (http://www.rubyonrails.com)
#++

require 'facet/class/descendents'

class Class

  def remove_descendents
    self.descendents.each do |subclass|
      Object.send(:remove_const, subclass.name) rescue nil
    end
    ObjectSpace.garbage_collect
  end

  alias_method :remove_subclasses, :remove_descendents

end



#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCClass < Test::Unit::TestCase

    class A ; end
    class B < A ; end
    class C < B ; end

    def test_remove_descendents
      assert_nothing_raised { B.remove_descendents }
      # doesn't work despite above; not sure why
      #assert_equal( [B], A.descendents )
    end

  end

=end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
facets-1.0.0 lib/facet/class/remove_descendents.rb
facets-1.0.3 packages/core/lib/facet/class/remove_descendents.rb
facets-1.3.0 lib/facets/core/class/remove_descendents.rb
facets-1.1.0 lib/facet/class/remove_descendents.rb
facets-1.2.0 lib/facets/core/class/remove_descendents.rb
facets-1.2.1 lib/facets/core/class/remove_descendents.rb
facets-1.3.2 lib/facets/core/class/remove_descendents.rb
facets-1.3.1 lib/facets/core/class/remove_descendents.rb
facets-1.3.3 lib/facets/core/class/remove_descendents.rb
facets-1.4.1 lib/facets/core/class/remove_descendents.rb
facets-1.4.0 lib/facets/core/class/remove_descendents.rb
facets-1.4.2 lib/facets/core/class/remove_descendents.rb
facets-1.4.3 lib/facets/core/class/remove_descendents.rb
facets-1.4.4 lib/facets/core/class/remove_descendents.rb
facets-1.4.5 lib/facets/core/class/remove_descendents.rb
facets-1.7.0 lib/facets/core/class/remove_descendents.rb
facets-1.7.30 lib/facets/core/class/remove_descendents.rb
facets-1.7.38 lib/facets/core/class/remove_descendents.rb
facets-1.7.46 lib/facets/core/class/remove_descendents.rb
facets-1.8.0 lib/facets/core/class/remove_descendents.rb