Module: Circuits::Component

Included in:
And, Nand, Nor, Not, Or, SrNand, SrNor, Xnor, Xor
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

Instance Method Summary collapse

Instance Attribute Details

#inputsObject (readonly)

Returns the value of attribute inputs.



29
30
31
# File 'lib/circuits/component.rb', line 29

def inputs
  @inputs
end

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

Parameters:

  • opts (Hash) (defaults to: {})

    options to create the Component with

Options Hash (opts):

  • :inputs (Array<Input>)

    The array of inputs to use



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

#tickObject

Does the internal computation and sets the outputs



20
21
22
# File 'lib/circuits/component.rb', line 20

def tick
  fail NotImplementedError
end

#tockObject

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