Class: Soroban::Walker

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/soroban/walker.rb

Overview

An enumerable that allows cells in a range to be visited.

Instance Method Summary collapse

Constructor Details

#initialize(range, binding) ⇒ Walker

Create a new walker from a supplied range and binding. The binding is required when calculating the value of each visited cell.



10
11
12
13
# File 'lib/soroban/walker.rb', line 10

def initialize(range, binding)
  @binding = binding
  @fc, @fr, @tc, @tr = Soroban::getRange(range)
end

Instance Method Details

#eachObject

Yield the value of each cell referenced by the supplied range.



16
17
18
19
20
21
22
# File 'lib/soroban/walker.rb', line 16

def each
  (@fc..@tc).each do |col|
    (@fr..@tr).each do |row|
      yield eval("@#{col}#{row}.get", @binding)
    end
  end
end