Class: Abstractable::PedigreeStream

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/abstractable/pedigree_stream.rb

Overview

this class represent stream of pedigree to myself from an ancestor.

Direct Known Subclasses

SingletonPedigreeStream

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ PedigreeStream

Returns a new instance of PedigreeStream.



6
7
8
9
# 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

Instance Method Details

#descendants_of(klass) ⇒ Object

descendants_of(klass) -> array Returns an array of descendants name of class.



43
44
45
46
# File 'lib/abstractable/pedigree_stream.rb', line 43

def descendants_of(klass)
  i = pedigree_stream.index(klass)
  i ? pedigree_stream.drop(i + 1) : []
end

#eachObject

each for Enumerable.



12
13
14
# File 'lib/abstractable/pedigree_stream.rb', line 12

def each
  pedigree_stream.each { |klass| yield klass }
end

#each_with_descendantsObject

each with descendants

Example of use: each_with_descendants do |klass, descendants_of_klass|

your code...

end



22
23
24
25
26
# 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) ⇒ Object

each_with_object with descendants.

Example of use: each_with_descendants_and_object([]) do |klass, descendants_of_klass, array|

your code...

end



34
35
36
37
38
39
# 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