Class: Logicuit::Signals::Clock
- Inherits:
-
Object
- Object
- Logicuit::Signals::Clock
- Defined in:
- lib/logicuit/signals/clock.rb
Overview
Clock
Instance Attribute Summary collapse
-
#downstreams ⇒ Object
readonly
Returns the value of attribute downstreams.
-
#tick_count ⇒ Object
readonly
Returns the value of attribute tick_count.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Clock
constructor
A new instance of Clock.
- #tick ⇒ Object
Constructor Details
#initialize ⇒ Clock
Returns a new instance of Clock.
7 8 9 10 |
# File 'lib/logicuit/signals/clock.rb', line 7 def initialize @downstreams = [] @tick_count = 0 end |
Instance Attribute Details
#downstreams ⇒ Object (readonly)
Returns the value of attribute downstreams.
12 13 14 |
# File 'lib/logicuit/signals/clock.rb', line 12 def downstreams @downstreams end |
#tick_count ⇒ Object (readonly)
Returns the value of attribute tick_count.
12 13 14 |
# File 'lib/logicuit/signals/clock.rb', line 12 def tick_count @tick_count end |
Class Method Details
.connects_to(component) ⇒ Object Also known as: >>
29 30 31 |
# File 'lib/logicuit/signals/clock.rb', line 29 def connects_to(component) instance.downstreams << component end |
.instance ⇒ Object
25 26 27 |
# File 'lib/logicuit/signals/clock.rb', line 25 def instance @instance ||= new end |
.tick ⇒ Object
34 35 36 |
# File 'lib/logicuit/signals/clock.rb', line 34 def tick instance.tick end |
.tick_count ⇒ Object
38 39 40 |
# File 'lib/logicuit/signals/clock.rb', line 38 def tick_count instance.tick_count end |
Instance Method Details
#tick ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/logicuit/signals/clock.rb', line 14 def tick @tick_count += 1 # Call the `evaluate` method for all components. # However, the input argument values should be bound to the values at the time `tick` is called. @downstreams.map do |component| args = component.input_targets.map { |input| component.instance_variable_get("@#{input}").current } -> { component.evaluate(*args) } end.each(&:call) end |