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
the inputs of this component.
-
#outputs ⇒ Object
readonly
the outputs of this component.
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)
the inputs of this component
33 34 35 |
# File 'lib/circuits/component.rb', line 33 def inputs @inputs end |
#outputs ⇒ Object (readonly)
the outputs of this component
36 37 38 |
# File 'lib/circuits/component.rb', line 36 def outputs @outputs end |
Instance Method Details
#initialize(opts = {}) ⇒ Object
Creates the Component with inputs and outputs
13 14 15 16 17 18 19 20 |
# File 'lib/circuits/component.rb', line 13 def initialize(opts = {}) @inputs = opts[:inputs] if opts[:inputs].is_a? Array @inputs = create_inputs opts[:inputs] if opts[:inputs].is_a? Integer @inputs = create_inputs input_count if opts[:inputs].nil? @outputs = output_count.times.collect { Circuits::Terminal::Output.new } setup end |
#tick ⇒ Object
Does the internal computation and sets the outputs
23 24 25 |
# File 'lib/circuits/component.rb', line 23 def tick fail NotImplementedError end |
#tock ⇒ Object
Sets all the outputs expose what was set in #tick
28 29 30 |
# File 'lib/circuits/component.rb', line 28 def tock outputs.each(&:tock) end |