Class: Rbkit::Timer
- Inherits:
-
Object
- Object
- Rbkit::Timer
- Defined in:
- lib/rbkit/timer.rb
Instance Attribute Summary collapse
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#last_fired_at ⇒ Object
Returns the value of attribute last_fired_at.
Instance Method Summary collapse
-
#initialize(interval, &timer_block) ⇒ Timer
constructor
A new instance of Timer.
- #run ⇒ Object
Constructor Details
#initialize(interval, &timer_block) ⇒ Timer
Returns a new instance of Timer.
5 6 7 8 9 |
# File 'lib/rbkit/timer.rb', line 5 def initialize(interval, &timer_block) @interval = interval @timer_block = timer_block @last_fired_at = Time.now end |
Instance Attribute Details
#interval ⇒ Object
Returns the value of attribute interval.
3 4 5 |
# File 'lib/rbkit/timer.rb', line 3 def interval @interval end |
#last_fired_at ⇒ Object
Returns the value of attribute last_fired_at.
3 4 5 |
# File 'lib/rbkit/timer.rb', line 3 def last_fired_at @last_fired_at end |
Instance Method Details
#run ⇒ Object
11 12 13 14 15 16 |
# File 'lib/rbkit/timer.rb', line 11 def run if Time.now - last_fired_at > interval @timer_block.call @last_fired_at = Time.now end end |