Class: Cadence::Computer::Counter
- Inherits:
-
Object
- Object
- Cadence::Computer::Counter
- Defined in:
- lib/cadence/computer/counter.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
-
#triggers ⇒ Object
Returns the value of attribute triggers.
Instance Method Summary collapse
- #every(n = 1, &block) ⇒ Object
-
#initialize(count = 0) ⇒ Counter
constructor
A new instance of Counter.
- #n ⇒ Object
- #next ⇒ Object
Constructor Details
#initialize(count = 0) ⇒ Counter
Returns a new instance of Counter.
5 6 7 8 |
# File 'lib/cadence/computer/counter.rb', line 5 def initialize(count = 0) @count = 0 @triggers = {} end |
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
3 4 5 |
# File 'lib/cadence/computer/counter.rb', line 3 def count @count end |
#triggers ⇒ Object
Returns the value of attribute triggers.
3 4 5 |
# File 'lib/cadence/computer/counter.rb', line 3 def triggers @triggers end |
Instance Method Details
#every(n = 1, &block) ⇒ Object
10 11 12 |
# File 'lib/cadence/computer/counter.rb', line 10 def every(n = 1, &block) @triggers[n] = block end |
#n ⇒ Object
21 22 23 |
# File 'lib/cadence/computer/counter.rb', line 21 def n @count end |
#next ⇒ Object
14 15 16 17 18 19 |
# File 'lib/cadence/computer/counter.rb', line 14 def next @count += 1 @triggers.each do |(n, trigger)| instance_eval(&trigger) if @count % n == 0 end end |