Class: Oscillo::BoolSignal

Inherits:
Signal
  • Object
show all
Defined in:
lib/oscillo/bool_signal.rb

Overview

A signal that operates on boolean values.

Instance Method Summary collapse

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.

Overloads:

  • #initialize(*signals) {|*signals, self| ... } ⇒ BoolSignal

    Follows some number of other signals, changing when they change.

    Parameters:

    • signals (Signal)

      the signals to follow

    Yields:

    • (*signals, self)

      gives the new values of the signals to the block

  • #initialize(start_value, *signals) {|*signals, self| ... } ⇒ BoolSignal

    Starts with an initial value and follows other signals when they change.

    Parameters:

    • start_value

      the initial value of this signal

    • signals (Signal)

      the signals to follow

    Yields:

    • (*signals, self)

      gives the new values of the signals to the block



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.

Parameters:

Returns:



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.

Parameters:

Returns:



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.

Parameters:

Returns:



53
54
55
# File 'lib/oscillo/bool_signal.rb', line 53

def nor(*signals)
  self.or(*signals).not
end

#notSignal Also known as: !

Negates the signal. i.e if the original signal was true, the new signal is false and vice versa.

Returns:



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.

Parameters:

Returns:



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.

Parameters:

Returns:



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.

Parameters:

Returns:



62
63
64
# File 'lib/oscillo/bool_signal.rb', line 62

def xor(signal)
  self.class.new(self, signal) { |a, b| a ^ b }
end