Class: Oscillo::BoolSignal
Overview
A signal that operates on boolean values.
Instance Method Summary collapse
-
#and(*signals) ⇒ Signal
(also: #&)
The new signal is true if all of the given signals are true, otherwise it is false.
-
#initialize(&block) ⇒ BoolSignal
constructor
Creates a new Signal with an optional initial value, signals to follow, and block.
-
#nand(*signals) ⇒ Signal
The new signal is true if all of the given signals are false, otherwise it is true.
-
#nor(*signals) ⇒ Signal
The new signal is true if any of the given signals are false, otherwise it is false.
-
#not ⇒ Signal
(also: #!)
Negates the signal.
-
#or(*signals) ⇒ Signal
(also: #|)
The new signal is true if any of the given signals are true, otherwise it is false.
-
#xnor(signal) ⇒ Signal
The new signal is true if only one of the given signals are false, otherwise it is false.
-
#xor(signal) ⇒ Signal
(also: #^)
The new signal is true if only one of the given signals are true, otherwise it is false.
Methods inherited from Signal
#abort, #change, #dont_follow, #drop_repeats, #follow, #on_change, #sample_on, #source, #to_i, #to_s, #update, #value
Methods included from Enumerable
#all?, #any?, #collect, #count, #each, #find_all, #inject, #reject, #zip
Constructor Details
#initialize(*signals) {|*signals, self| ... } ⇒ BoolSignal #initialize(start_value, *signals) {|*signals, self| ... } ⇒ BoolSignal
Creates a new Signal with an optional initial value, signals to follow, and block. The block converts the values from any signals that this one follows to the value of this signal. If no block is given, the value will be an array of all the values of the signals that it follows (or if it is just following one signal, the value of that signal).
Defaults to false instead of nil.
6 7 8 |
# File 'lib/oscillo/bool_signal.rb', line 6 def initialize(*, &block) @value = false; super end |
Instance Method Details
#and(*signals) ⇒ Signal Also known as: &
The new signal is true if all of the given signals are true, otherwise it is false.
24 25 26 |
# File 'lib/oscillo/bool_signal.rb', line 24 def and(*signals) self.class.new(self, *signals) { |*vs, s| vs.all? } end |
#nand(*signals) ⇒ Signal
The new signal is true if all of the given signals are false, otherwise it is true.
34 35 36 |
# File 'lib/oscillo/bool_signal.rb', line 34 def nand(*signals) self.and(*signals).not end |
#nor(*signals) ⇒ Signal
The new signal is true if any of the given signals are false, otherwise it is false.
53 54 55 |
# File 'lib/oscillo/bool_signal.rb', line 53 def nor(*signals) self.or(*signals).not end |
#not ⇒ Signal Also known as: !
Negates the signal. i.e if the original signal was true, the new signal is false and vice versa.
14 15 16 |
# File 'lib/oscillo/bool_signal.rb', line 14 def not self.class.new(self) { |v| !v } end |
#or(*signals) ⇒ Signal Also known as: |
The new signal is true if any of the given signals are true, otherwise it is false.
43 44 45 |
# File 'lib/oscillo/bool_signal.rb', line 43 def or(*signals) self.class.new(self, *signals) { |*vs, s| vs.any? } end |
#xnor(signal) ⇒ Signal
The new signal is true if only one of the given signals are false, otherwise it is false.
72 73 74 |
# File 'lib/oscillo/bool_signal.rb', line 72 def xnor(signal) self.xor(signal).not end |
#xor(signal) ⇒ Signal Also known as: ^
The new signal is true if only one of the given signals are true, otherwise it is false.
62 63 64 |
# File 'lib/oscillo/bool_signal.rb', line 62 def xor(signal) self.class.new(self, signal) { |a, b| a ^ b } end |