rcircuit/or.rb

21 lines
386 B
Ruby
Raw Normal View History

2018-07-09 16:24:50 -05:00
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