Class: Enumerable::TriggerPartitionContext
- Defined in:
- lib/util/trigger_partition.rb
Instance Method Summary collapse
- #emit ⇒ Object
- #fill(&block) ⇒ Object
-
#initialize(enum, &block) ⇒ TriggerPartitionContext
constructor
A new instance of TriggerPartitionContext.
Constructor Details
#initialize(enum, &block) ⇒ TriggerPartitionContext
Returns a new instance of TriggerPartitionContext.
3 4 5 6 |
# File 'lib/util/trigger_partition.rb', line 3 def initialize(enum, &block) @enum = enum @cont = block end |
Instance Method Details
#emit ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/util/trigger_partition.rb', line 11 def emit partitions = [] cont = @cont fill = @fill p = @enum.inject(nil) do |part, elem| if part && cont.call(part, elem) fill.call(part, elem) part else partitions << part if part yield(elem) end end partitions << p if p partitions end |
#fill(&block) ⇒ Object
7 8 9 10 |
# File 'lib/util/trigger_partition.rb', line 7 def fill(&block) @fill = block self end |