Module: Lab419::Enumerable::Pair
Instance Method Summary collapse
Instance Method Details
#pairs(enum, options = {}, &blk) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/lab419/core/enumerable/pair.rb', line 5 def pairs enum, ={}, &blk enum.each_with_index do | e1, i1 | enum.each_with_index do | e2, i2 | next if i2 < i1 || i2 == i1 && ![:reflexive] blk.( [e1, e2 ] ) end end end |
#pairs_with_rest(enum, options = {}, &blk) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/lab419/core/enumerable/pair.rb', line 13 def pairs_with_rest enum, ={}, &blk x = enum.to_a enum.each_with_index do | e1, i1 | enum.each_with_index do | e2, i2 | next if i2 < i1 || i2 == i1 && ![:reflexive] blk.( [[e1, e2 ], x.without_indices(i1,i2)] ) end end end |