Sha256: c03f3ab4d01e55e291046a60d0f9edf6c4be8b12ec5c94d6d3c6e410108d7c8d
Contents?: true
Size: 719 Bytes
Versions: 10
Compression:
Stored size: 719 Bytes
Contents
# frozen_string_literal: true require 'forwardable' # rubocop:disable Style/ClassVars module Fortnox module API class CircularQueue extend Forwardable def initialize(*items) @queue = [*items] @@next_index = random_start_index end # support some general Array methods that fit Queues well def_delegators :@queue, :new, :[], :size def next value = @queue[@@next_index] if @@next_index == size - 1 @@next_index = 0 else @@next_index += 1 end value end private def random_start_index Random.rand(@queue.size) end end end end # rubocop:enable Style/ClassVars
Version data entries
10 entries across 10 versions & 1 rubygems