Sha256: 60901ac69ebd3364d34d19410714d7d5ee4a9d5eab5145708c8e92b8113edf1a

Contents?: true

Size: 747 Bytes

Versions: 3

Compression:

Stored size: 747 Bytes

Contents

# Original code from RubyOnRails (http://www.rubyonrails.com)
#--
# TODO: suggest inclusion in Facets.
#++

class Object #:nodoc:
  def remove_subclasses_of(superclass)
    subclasses_of(superclass).each do |subclass| 
      Object.send(:remove_const, subclass) rescue nil 
    end
  end

  def subclasses_of(superclass)
    subclasses = []
    ObjectSpace.each_object(Class) do |c|
      if c.ancestors.include?(superclass) and superclass != c
        subclasses << c
      end
    end
    return subclasses
  end
end

class Class #:nodoc:
  def remove_subclasses
    Object.remove_subclasses_of(self)
  end

  def subclasses
    Object.subclasses_of(self)
  end
  alias_method :descendants, :subclasses
end

# * George Moschovitis <gm@navel.gr>

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
glue-0.22.0 lib/glue/object.rb
glue-0.21.0 lib/glue/object.rb
glue-0.21.2 lib/glue/object.rb