Sha256: a101153c22826b93e1fdaaef1e9a7c5e6348305f5ccca4f0654aed4208f87ec3
Contents?: true
Size: 931 Bytes
Versions: 14
Compression:
Stored size: 931 Bytes
Contents
require 'active_support/core_ext/module/anonymous' require 'active_support/core_ext/module/reachable' class Class begin ObjectSpace.each_object(Class.new) {} def descendants # :nodoc: descendants = [] ObjectSpace.each_object(singleton_class) do |k| descendants.unshift k unless k == self end descendants end rescue StandardError # JRuby def descendants # :nodoc: descendants = [] ObjectSpace.each_object(Class) do |k| descendants.unshift k if k < self end descendants.uniq! descendants end end # Returns an array with the direct children of +self+. # # class Foo; end # class Bar < Foo; end # class Baz < Bar; end # # Foo.subclasses # => [Bar] def subclasses subclasses, chain = [], descendants chain.each do |k| subclasses << k unless chain.any? { |c| c > k } end subclasses end end
Version data entries
14 entries across 14 versions & 3 rubygems