Class: Logicuit::Signals::Signal

Inherits:
Object
  • Object
show all
Defined in:
lib/logicuit/signals/signal.rb

Overview

Signal

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current = false) ⇒ Signal

Returns a new instance of Signal.



7
8
9
10
# File 'lib/logicuit/signals/signal.rb', line 7

def initialize(current = false)
  @current = current
  @downstreams = []
end

Instance Attribute Details

#currentObject (readonly)

Returns the value of attribute current.



12
13
14
# File 'lib/logicuit/signals/signal.rb', line 12

def current
  @current
end

Instance Method Details

#!Object



52
53
54
# File 'lib/logicuit/signals/signal.rb', line 52

def !
  Signal.new(!current)
end

#&(other) ⇒ Object



44
45
46
# File 'lib/logicuit/signals/signal.rb', line 44

def &(other)
  Signal.new(current && other.current)
end

#connects_to(other) ⇒ Object Also known as: >>



28
29
30
31
32
33
34
35
36
37
# File 'lib/logicuit/signals/signal.rb', line 28

def connects_to(other)
  if other.is_a? Array
    @downstreams.concat(other)
  elsif other.is_a? Signals::SignalGroup
    @downstreams.concat(other.signals)
  else
    @downstreams << other
  end
  propagate_current
end

#offObject



21
22
23
24
25
26
# File 'lib/logicuit/signals/signal.rb', line 21

def off
  return unless @current

  @current = false
  propagate_current
end

#onObject



14
15
16
17
18
19
# File 'lib/logicuit/signals/signal.rb', line 14

def on
  return if @current

  @current = true
  propagate_current
end

#to_sObject



40
41
42
# File 'lib/logicuit/signals/signal.rb', line 40

def to_s
  current ? "1" : "0"
end

#|(other) ⇒ Object



48
49
50
# File 'lib/logicuit/signals/signal.rb', line 48

def |(other)
  Signal.new(current || other.current)
end