lib/bluepill/util/rotational_array.rb in bluepill-0.0.28 vs lib/bluepill/util/rotational_array.rb in bluepill-0.0.30
- old
+ new
@@ -46,9 +46,17 @@
def clear
@counter = 0
super
end
+ def each(&block)
+ times = @counter >= @capacity ? @capacity : @counter
+ start = @counter >= @capacity ? rotational_idx(@counter) : 0
+ times.times do |i|
+ block.call(self[rotational_idx(start + i)])
+ end
+ end
+
private
def rotational_idx(idx)
idx % @capacity
end