Module: Circuits::Component
- Defined in:
- lib/circuits/component.rb,
lib/circuits/component/or.rb,
lib/circuits/component/and.rb,
lib/circuits/component/nor.rb,
lib/circuits/component/not.rb,
lib/circuits/component/xor.rb,
lib/circuits/component/nand.rb,
lib/circuits/component/xnor.rb,
lib/circuits/component/sr_nor.rb,
lib/circuits/component/sr_nand.rb
Overview
A component has a set of inputs an outputs. Every tick a componnent computes its outputs, but the componnent will wait for the tock before the componnent updates its own outputs
Defined Under Namespace
Classes: And, Nand, Nor, Not, Or, SrNand, SrNor, Xnor, Xor
Instance Attribute Summary collapse
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#outputs ⇒ Object
readonly
Returns the value of attribute outputs.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Object
Creates the Component with inputs and outputs.
-
#tick ⇒ Object
Does the internal computation and sets the outputs.
-
#tock ⇒ Object
Sets all the outputs expose what was set in #tick.
Instance Attribute Details
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
29 30 31 |
# File 'lib/circuits/component.rb', line 29 def inputs @inputs end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
29 30 31 |
# File 'lib/circuits/component.rb', line 29 def outputs @outputs end |
Instance Method Details
#initialize(opts = {}) ⇒ Object
Creates the Component with inputs and outputs
12 13 14 15 16 17 |
# File 'lib/circuits/component.rb', line 12 def initialize(opts = {}) @inputs = opts[:inputs] || input_count.times.collect { Circuits::Terminal::Input.new } @outputs = output_count.times.collect { Circuits::Terminal::Output.new } setup end |
#tick ⇒ Object
Does the internal computation and sets the outputs
20 21 22 |
# File 'lib/circuits/component.rb', line 20 def tick fail NotImplementedError end |
#tock ⇒ Object
Sets all the outputs expose what was set in #tick
25 26 27 |
# File 'lib/circuits/component.rb', line 25 def tock outputs.each(&:tock) end |