class Abstractable::PedigreeStream
this class represent stream of pedigree to myself from an ancestor.
Attributes
pedigree_stream[RW]
Public Class Methods
new(klass)
click to toggle source
# File lib/abstractable/pedigree_stream.rb, line 6 def initialize(klass) fail ArgumentError, "wrong type argument #{klass} (should be Class) " unless klass.is_a? Class self.pedigree_stream = pedigree_stream_of(klass) end
Public Instance Methods
descendants_of(klass)
click to toggle source
descendants_of
(klass) -> array Returns an array of descendants name of class.
# File lib/abstractable/pedigree_stream.rb, line 43 def descendants_of(klass) i = pedigree_stream.index(klass) i ? pedigree_stream.drop(i + 1) : [] end
each() { |klass| ... }
click to toggle source
each for Enumerable.
# File lib/abstractable/pedigree_stream.rb, line 12 def each pedigree_stream.each { |klass| yield klass } end
each_with_descendants() { |klass, descendants_of(klass)| ... }
click to toggle source
each with descendants
Example of use: each_with_descendants
do |klass, descendants_of_klass|
your code...
end
# File lib/abstractable/pedigree_stream.rb, line 22 def each_with_descendants each do |klass| yield(klass, descendants_of(klass)) end end
each_with_descendants_and_object(object) { |klass, descendants_of_klass, object| ... }
click to toggle source
each_with_object with descendants.
Example of use: each_with_descendants_and_object
([]) do |klass, descendants_of_klass, array|
your code...
end
# File lib/abstractable/pedigree_stream.rb, line 34 def each_with_descendants_and_object(object) each_with_descendants do |klass, descendants_of_klass| yield(klass, descendants_of_klass, object) end object end
Protected Instance Methods
pedigree_stream_of(klass)
click to toggle source
# File lib/abstractable/pedigree_stream.rb, line 52 def pedigree_stream_of(klass) klass.ancestors.reverse end