Class: TFG::Support::Sequence

Inherits:
Object
  • Object
show all
Defined in:
lib/tfg/support/sequence.rb

Instance Method Summary collapse

Constructor Details

#initialize(first, generator = nil, &block) ⇒ Sequence

Returns a new instance of Sequence.



4
5
6
7
# File 'lib/tfg/support/sequence.rb', line 4

def initialize(first, generator=nil, &block)
  self.first = first
  self.generator = generator || block
end

Instance Method Details

#nextObject



9
10
11
12
13
14
15
# File 'lib/tfg/support/sequence.rb', line 9

def next
  if previous
    self.previous = generator.call(previous)
  else
    self.previous = first
  end
end