Class: Logicuit::Signals::Clock

Inherits:
Object
  • Object
show all
Defined in:
lib/logicuit/signals/clock.rb

Overview

Clock

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClock

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

#downstreamsObject (readonly)

Returns the value of attribute downstreams.



12
13
14
# File 'lib/logicuit/signals/clock.rb', line 12

def downstreams
  @downstreams
end

#tick_countObject (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

.instanceObject



25
26
27
# File 'lib/logicuit/signals/clock.rb', line 25

def instance
  @instance ||= new
end

.tickObject



34
35
36
# File 'lib/logicuit/signals/clock.rb', line 34

def tick
  instance.tick
end

.tick_countObject



38
39
40
# File 'lib/logicuit/signals/clock.rb', line 38

def tick_count
  instance.tick_count
end

Instance Method Details

#tickObject



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