Sha256: 8c02e056e8fd686dd2bd56091b085ccc9524e65b19db78c6f3aaf361aa7b8b6b

Contents?: true

Size: 795 Bytes

Versions: 1

Compression:

Stored size: 795 Bytes

Contents

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

require 'nano/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

1 entries across 1 versions & 1 rubygems

Version Path
facets-0.9.0 lib/nano/class/remove_descendents.rb