Class: Circuits::Component::And

Inherits:
Base
  • Object
show all
Defined in:
lib/circuits/component/and.rb

Overview

Logical AND Operator

Instance Attribute Summary

Attributes inherited from Base

#inputs, #outputs

Instance Method Summary collapse

Methods inherited from Base

#[], #tock

Constructor Details

#initialize(opts = {}) ⇒ And

Returns a new instance of And.



7
8
9
10
# File 'lib/circuits/component/and.rb', line 7

def initialize(opts = {})
  inputs = opts[:inputs] || 2
  super(inputs: inputs, outputs: 1)
end

Instance Method Details

#tickObject

Sets the output to be the result of a logical AND of the inputs



13
14
15
# File 'lib/circuits/component/and.rb', line 13

def tick
  self[:out].set(inputs.map(&:get).inject(:&))
end