Module: Utilities::Subclasses

Defined in:
lib/utilities.rb

Instance Method Summary collapse

Instance Method Details

#subclasses(direct = false) ⇒ Object

Find every subclass of an object.



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/utilities.rb', line 104

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