From 99bd54a7a0350f255c3cba01a4774eb6aaedc9ee Mon Sep 17 00:00:00 2001 From: pjht Date: Sun, 15 Jul 2018 16:29:21 -0500 Subject: [PATCH] Add logic methods on Port class --- lib/rcircuit/port.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/rcircuit/port.rb b/lib/rcircuit/port.rb index c09d68d..0669214 100644 --- a/lib/rcircuit/port.rb +++ b/lib/rcircuit/port.rb @@ -79,6 +79,33 @@ class Port end end + # Returns the output port of an AND gate with this port and another as inputs + # @param other [Port] The port to AND with + # @return [Port] The output port of the gate + def &(other) + return AndGate.new(self,other).out + end + + # Returns the output port of an OR gate with this port and another as inputs + # @param other [Port] The port to OR with + # @return [Port] The output port of the gate + def |(other) + return OrGate.new(self,other).out + end + + # Returns the output port of an XOR gate with this port and another as inputs + # @param other [Port] The port to XOR with + # @return [Port] The output port of the gate + def ^(other) + return XorGate.new(self, other).out + end + + # Returns the output port of a NOT gate with this port as the input + # @return [Port] The output port of the gate + def ! + return NotGate.new(self).out + end + # Used by connect when setting up bidirectional connection. # @api private # @param (see #connect)