Class: Logicuit::Signals::Signal
- Inherits:
-
Object
- Object
- Logicuit::Signals::Signal
- Defined in:
- lib/logicuit/signals/signal.rb
Overview
Signal
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
Instance Method Summary collapse
- #connects_to(other) ⇒ Object (also: #>>)
-
#initialize(current = false) ⇒ Signal
constructor
A new instance of Signal.
- #off ⇒ Object
- #on ⇒ Object
- #to_s ⇒ Object
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
#current ⇒ Object (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
#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 |
#off ⇒ Object
21 22 23 24 25 26 |
# File 'lib/logicuit/signals/signal.rb', line 21 def off return unless @current @current = false propagate_current end |
#on ⇒ Object
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_s ⇒ Object
40 41 42 |
# File 'lib/logicuit/signals/signal.rb', line 40 def to_s current ? "1" : "0" end |