Module: VirtualBox::SubclassListing::ClassMethods

Defined in:
lib/virtualbox/ext/subclass_listing.rb

Instance Method Summary collapse

Instance Method Details

#subclasses(direct = false) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/virtualbox/ext/subclass_listing.rb', line 8

def subclasses(direct = false)
  classes = []
  if direct
    ObjectSpace.each_object(Class) do |c|
      next unless c.superclass == self
      classes << c
    end
  else
    ObjectSpace.each_object(Class) do |c|
      next unless c.ancestors.include?(self) and (c != self)
      classes << c
    end
  end
  classes
end