Module: LogicGates

Defined in:
lib/logicgates.rb,
lib/logicgates/version.rb

Constant Summary collapse

VERSION =
"0.0.6"

Class Method Summary collapse

Class Method Details

.mux(a, b, s) ⇒ Object



31
32
33
# File 'lib/logicgates.rb', line 31

def self.mux(a, b, s)
  my_or(my_and(a, not(s)), my_and(b, s))
end

.my_and(a, b) ⇒ Object



3
4
5
# File 'lib/logicgates.rb', line 3

def self.my_and(a, b)
  a && b
end

.my_or(a, b) ⇒ Object



7
8
9
# File 'lib/logicgates.rb', line 7

def self.my_or(a, b)
  a || b
end

.nand(a, b) ⇒ Object



23
24
25
# File 'lib/logicgates.rb', line 23

def self.nand(a, b)
  not(my_and(a, b))
end

.nor(a, b) ⇒ Object



19
20
21
# File 'lib/logicgates.rb', line 19

def self.nor(a, b)
  not(my_or(a, b))
end

.not(a) ⇒ Object



11
12
13
# File 'lib/logicgates.rb', line 11

def self.not(a)
  !a
end

.xnor(a, b) ⇒ Object



27
28
29
# File 'lib/logicgates.rb', line 27

def self.xnor(a, b)
  not(xor(a, b))
end

.xor(a, b) ⇒ Object



15
16
17
# File 'lib/logicgates.rb', line 15

def self.xor(a, b)
  my_and(my_or(a, b), not(my_and(a, b)))
end