Module Hobix::Enumerable
In: lib/hobix/base.rb

Enumerable::each_with_neighbors from Joel Vanderwerf‘s enum extenstions.

Methods

Public Instance methods

[Source]

     # File lib/hobix/base.rb, line 200
200:     def each_with_neighbors n = 1, empty = nil
201:         nbrs = [empty] * (2 * n + 1)
202:         offset = n
203: 
204:         each { |x|
205:             nbrs.shift
206:             nbrs.push x
207:             if offset == 0  # offset is now the offset of the first element, x0,
208:                 yield nbrs    #   of the sequence from the center of nbrs, or 0,
209:             else            #   if x0 has already passed the center.
210:                 offset -= 1
211:             end
212:         }
213: 
214:         n.times {
215:             nbrs.shift
216:             nbrs.push empty
217:             if offset == 0
218:                 yield nbrs
219:             else
220:                 offset -= 1
221:             end
222:         }
223: 
224:         self
225:     end

[Validate]