Class: Dilation::Timers::Timer Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/dilation/timers/timer.rb

Overview

This class is abstract.

Subclass and override #start and #stop

Author:

Direct Known Subclasses

Coarse, Test

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ Timer

Returns a new instance of Timer.

Parameters:

  • target (#tick)

    the object to notify on ticks



8
9
10
# File 'lib/dilation/timers/timer.rb', line 8

def initialize(target)
  @target = target
end

Instance Method Details

#running?Boolean

Returns true if this timer is running.

Returns:

  • (Boolean)

    true if this timer is running



18
19
20
# File 'lib/dilation/timers/timer.rb', line 18

def running?
  defined?(@started) && @started
end

#startObject

Start this timer



28
29
30
# File 'lib/dilation/timers/timer.rb', line 28

def start
  @started = true
end

#stopObject

Stop this timer



23
24
25
# File 'lib/dilation/timers/timer.rb', line 23

def stop
  @started = false
end

#tickObject

This method should be called by subclasses on each tick



13
14
15
# File 'lib/dilation/timers/timer.rb', line 13

def tick
  @target.tick
end