rcircuit/or.rb
2018-07-09 16:24:50 -05:00

21 lines
386 B
Ruby

require_relative "gate.rb"
require_relative "port.rb"
# Represents an OR gate
class OrGate < Gate
# Called when inputs change.
# Calculates OR of all inputs and sets output port to that value.
def inputs_changed(vals)
orval=nil
vals.each do |val|
if orval==nil
orval=val
else
orval=orval|val
end
end
out.setval(orval)
end
end