Class: EnumerableOperator::Product
- Includes:
- Enumerable
- Defined in:
- lib/agents/sets/enum/op.rb
Instance Attribute Summary collapse
-
#dim ⇒ Object
readonly
Returns the value of attribute dim.
-
#factors ⇒ Object
readonly
Returns the value of attribute factors.
Instance Method Summary collapse
- #each(tuple = [nil]*@dim, i = 0, &block) ⇒ Object
-
#initialize(*factors) ⇒ Product
constructor
A new instance of Product.
- #size ⇒ Object
Methods included from Enumerable
#each_cluster, #each_with_neighbors, #group, nest, #nest, #pipe
Constructor Details
#initialize(*factors) ⇒ Product
Returns a new instance of Product.
12 13 14 15 |
# File 'lib/agents/sets/enum/op.rb', line 12 def initialize(*factors) @factors = factors @dim = @factors.length end |
Instance Attribute Details
#dim ⇒ Object (readonly)
Returns the value of attribute dim.
10 11 12 |
# File 'lib/agents/sets/enum/op.rb', line 10 def dim @dim end |
#factors ⇒ Object (readonly)
Returns the value of attribute factors.
10 11 12 |
# File 'lib/agents/sets/enum/op.rb', line 10 def factors @factors end |
Instance Method Details
#each(tuple = [nil]*@dim, i = 0, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/agents/sets/enum/op.rb', line 17 def each tuple = [nil]*@dim, i = 0, &block if i == @dim - 1 then @factors[i].each { |x| tuple[i] = x; yield tuple.dup } elsif i > 0 @factors[i].each { |x| tuple[i] = x; each tuple, i + 1, &block } else @factors[i].each { |x| tuple[i] = x; each tuple, i + 1, &block } self end end |
#size ⇒ Object
28 29 30 |
# File 'lib/agents/sets/enum/op.rb', line 28 def size @factors.product { |enum| enum.size } end |