class Lockfile::SleepCycle

Attributes

inc[R]
max[R]
min[R]
range[R]

Public Class Methods

new(min, max, inc) click to toggle source
# File lib/lockfile.rb, line 32
def initialize(min, max, inc)
  @min, @max, @inc = Float(min), Float(max), Float(inc)
  @range = @max - @min
  raise RangeError, "max(#{ @max }) <= min(#{ @min })" if @max <= @min
  raise RangeError, "inc(#{ @inc }) > range(#{ @range })" if @inc > @range
  raise RangeError, "inc(#{ @inc }) <= 0" if @inc <= 0
  raise RangeError, "range(#{ @range }) <= 0" if @range <= 0
  s = @min
  push(s) and s += @inc while(s <= @max)
  self[-1] = @max if self[-1] < @max
  reset
end

Public Instance Methods

next() click to toggle source
# File lib/lockfile.rb, line 45
def next
  ret = self[@idx]
  @idx = ((@idx + 1) % self.size)
  ret
end
reset() click to toggle source
# File lib/lockfile.rb, line 51
def reset
  @idx = 0
end