Class: Object

Inherits:
BasicObject
Defined in:
lib/glue/object.rb

Overview

Code from RubyOnRails (www.rubyonrails.com)

Instance Method Summary collapse

Instance Method Details

#remove_subclasses_of(superclass) ⇒ Object

:nodoc:



8
9
10
# File 'lib/glue/object.rb', line 8

def remove_subclasses_of(superclass)
  subclasses_of(superclass).each { |subclass| Object.send(:remove_const, subclass) rescue nil }
end

#subclasses_of(superclass) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/glue/object.rb', line 12

def subclasses_of(superclass)
  subclasses = []
  ObjectSpace.each_object(Class) do |k|
    next if !k.ancestors.include?(superclass) || superclass == k || k.to_s.include?("::") || subclasses.include?(k.to_s)
    subclasses << k.to_s
  end
  subclasses
end