Sha256: 0d63df1e65c89ef322243b2a9383a04b50fd1812943062ea0a096fcdde89b011

Contents?: true

Size: 561 Bytes

Versions: 31

Compression:

Stored size: 561 Bytes

Contents

# From: http://snippets.dzone.com/posts/show/2992
module VirtualBox::SubclassListing
  def self.included(base)
    base.extend ClassMethods
  end

  module ClassMethods
    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
  end
end

Version data entries

31 entries across 31 versions & 3 rubygems

Version Path
virtualbox-0.9.2 lib/virtualbox/ext/subclass_listing.rb
virtualbox-0.9.1 lib/virtualbox/ext/subclass_listing.rb
virtualbox-0.9.0 lib/virtualbox/ext/subclass_listing.rb
virtualbox-0.8.6 lib/virtualbox/ext/subclass_listing.rb
virtualbox-0.8.5 lib/virtualbox/ext/subclass_listing.rb
virtualbox-0.8.4 lib/virtualbox/ext/subclass_listing.rb
velir_virtualbox-0.8.4 lib/virtualbox/ext/subclass_listing.rb
virtualbox-0.8.3 lib/virtualbox/ext/subclass_listing.rb
virtualbox-0.8.2 lib/virtualbox/ext/subclass_listing.rb
virtualbox-0.8.1 lib/virtualbox/ext/subclass_listing.rb
virtualbox-0.8.0 lib/virtualbox/ext/subclass_listing.rb
virtualbox-0.7.9 lib/virtualbox/ext/subclass_listing.rb
virtualbox-0.7.8 lib/virtualbox/ext/subclass_listing.rb
virtualbox-0.7.7 lib/virtualbox/ext/subclass_listing.rb
virtualbox-0.7.6 lib/virtualbox/ext/subclass_listing.rb
bbrowning-virtualbox-0.7.6.dev lib/virtualbox/ext/subclass_listing.rb
virtualbox-0.7.5 lib/virtualbox/ext/subclass_listing.rb
virtualbox-0.7.4 lib/virtualbox/ext/subclass_listing.rb
virtualbox-0.7.3 lib/virtualbox/ext/subclass_listing.rb
virtualbox-0.7.2 lib/virtualbox/ext/subclass_listing.rb