Class: Grueserve::Rated::Rate

Inherits:
Object
  • Object
show all
Defined in:
lib/grueserve/rated.rb

Instance Method Summary collapse

Constructor Details

#initialize(n) ⇒ Rate

Returns a new instance of Rate.



24
25
26
27
# File 'lib/grueserve/rated.rb', line 24

def initialize(n)
  @n = n
  @times = {}
end

Instance Method Details

#times_a_second(&block) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/grueserve/rated.rb', line 28

def times_a_second(&block)
  time = (@times[:second] ||= Time.now.to_f)
  if Time.now.to_f - time > 1.0 / @n
    @times[:second] = Time.now.to_f
    yield
  end
end