rcircuit/xor.rb

21 lines
395 B
Ruby
Raw Normal View History

2018-07-09 16:24:50 -05:00
require_relative "gate.rb"
require_relative "port.rb"
# Represents an XOR gate
class XorGate < Gate
# Called when inputs change.
# Calculates XOR of all inputs and sets output port to that value.
def inputs_changed(vals)
xorval=nil
vals.each do |val|
if xorval==nil
xorval=val
else
xorval=xorval^val
end
end
out.setval(xorval)
end
end