Module: Capped

Defined in:
lib/capped.rb

Defined Under Namespace

Classes: LimitExceededError

Class Method Summary collapse

Class Method Details

.capped_until(limit, condition_proc) ⇒ Object Also known as: until



28
29
30
31
32
33
34
35
36
37
# File 'lib/capped.rb', line 28

def capped_until(limit, condition_proc)
  countdown = limit
  until condition_proc.call
    countdown -= 1
    if countdown < 0
      raise LimitExceededError.new("Condition not met after #{limit} iterations", limit)
    end
    yield
  end
end

.capped_while(limit, condition_proc) ⇒ Object Also known as: while



14
15
16
17
18
19
20
21
22
23
# File 'lib/capped.rb', line 14

def capped_while(limit, condition_proc)
  countdown = limit
  while condition_proc.call
    countdown -= 1
    if countdown < 0
      raise LimitExceededError.new("Condition not met after #{limit} iterations", limit)
    end
    yield
  end
end