• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jdantonio / concurrent-ruby / #712

24 Apr 2014 12:31AM UTC coverage: 77.896% (-19.9%) from 97.805%
#712

push

jdantonio
Attempting to fix a brittle test of Concurrent::timer.

1903 of 2443 relevant lines covered (77.9%)

541.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

35.71
/lib/concurrent/collection/ring_buffer.rb
1
module Concurrent
1✔
2

3
  # non-thread safe buffer
4
  class RingBuffer
1✔
5

6
    def initialize(capacity)
1✔
7
      @buffer = Array.new(capacity)
×
8
      @first = @last = 0
×
9
      @count = 0
×
10
    end
11

12

13
    # @return [Integer] the capacity of the buffer
14
    def capacity
1✔
15
      @buffer.size
×
16
    end
17

18
    # @return [Integer] the number of elements currently in the buffer
19
    def count
1✔
20
      @count
×
21
    end
22

23
    # @return [Boolean] true if buffer is empty, false otherwise
24
    def empty?
1✔
25
      @count == 0
×
26
    end
27

28
    # @return [Boolean] true if buffer is full, false otherwise
29
    def full?
1✔
30
      @count == capacity
×
31
    end
32

33
    # @param [Object] value
34
    # @return [Boolean] true if value has been inserted, false otherwise
35
    def offer(value)
1✔
36
      return false if full?
×
37

38
      @buffer[@last] = value
×
39
      @last = (@last + 1) % @buffer.size
×
40
      @count += 1
×
41
      true
×
42
    end
43

44
    # @return [Object] the first available value and removes it from the buffer. If buffer is empty returns nil
45
    def poll
1✔
46
      result = @buffer[@first]
×
47
      @buffer[@first] = nil
×
48
      @first = (@first + 1) % @buffer.size
×
49
      @count -= 1
×
50
      result
×
51
    end
52

53
    # @return [Object] the first available value and without removing it from the buffer. If buffer is empty returns nil
54
    def peek
1✔
55
      @buffer[@first]
×
56
    end
57

58
  end
59
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc