Class: EnumerableOperator::Diagonal

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/agents/sets/enum/op.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#each_cluster, #each_with_neighbors, #group, nest, #nest, #pipe

Constructor Details

#initialize(*factors) ⇒ Diagonal

Returns a new instance of Diagonal.



59
60
61
62
# File 'lib/agents/sets/enum/op.rb', line 59

def initialize(*factors)
  @factors = factors
  @dim = @factors.length
end

Instance Attribute Details

#dimObject (readonly)

Returns the value of attribute dim.



57
58
59
# File 'lib/agents/sets/enum/op.rb', line 57

def dim
  @dim
end

#factorsObject (readonly)

Returns the value of attribute factors.



57
58
59
# File 'lib/agents/sets/enum/op.rb', line 57

def factors
  @factors
end

Instance Method Details

#eachObject



64
65
66
67
68
69
70
71
72
73
# File 'lib/agents/sets/enum/op.rb', line 64

def each
  factors = @factors.map { |factor|
    if factor.kind_of? Array then factor else factor.entries end
  }
  minlength = factors.min { |f, g| f.length <=> g.length }.length
  for i in 0..(minlength-1)
    yield factors.map { |factor| factor[i] }
  end
  self
end