Module: Denko::Behaviors::Subcomponents
- Included in:
- BoardProxy, BusController, Denko::Board
- Defined in:
- lib/denko/behaviors/subcomponents.rb
Instance Method Summary collapse
- #add_component(component) ⇒ Object
- #components ⇒ Object
- #remove_component(component) ⇒ Object
- #single_pin_components ⇒ Object
Instance Method Details
#add_component(component) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/denko/behaviors/subcomponents.rb', line 12 def add_component(component) if component.respond_to?(:pin) && component.pin.class == Integer unless single_pin_components[component.pin] single_pin_components[component.pin] = component else raise StandardError, "Error adding #{component} to #{self}. Pin: #{component.pin} " \ "already in use by: #{single_pin_components[component.pin]}" end end components << component end |
#components ⇒ Object
4 5 6 |
# File 'lib/denko/behaviors/subcomponents.rb', line 4 def components @components ||= [] end |
#remove_component(component) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/denko/behaviors/subcomponents.rb', line 25 def remove_component(component) if component.respond_to?(:pin) && component.pin.class == Integer single_pin_components[component.pin] = nil end deleted = components.delete(component) component.stop if deleted && component.respond_to?(:stop) end |
#single_pin_components ⇒ Object
8 9 10 |
# File 'lib/denko/behaviors/subcomponents.rb', line 8 def single_pin_components @single_pin_components ||= {} end |