Class: Frankenpins::Button
- Inherits:
-
Object
- Object
- Frankenpins::Button
- Includes:
- Unobservable::Support
- Defined in:
- lib/frankenpins/button.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ Button
constructor
A new instance of Button.
- #when(event_name, &block) ⇒ Object
Constructor Details
#initialize(options) ⇒ Button
Returns a new instance of Button.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/frankenpins/button.rb', line 11 def initialize() [:pull] = :up unless .has_key?(:pull) @pin = Frankenpins::Pin.new() @pin.watch do |pin| if pin.value == 0 raise_event :pressed elsif pin.value == 1 raise_event :released end # Always fire a changed event raise_event :changed end end |
Instance Method Details
#when(event_name, &block) ⇒ Object
27 28 29 |
# File 'lib/frankenpins/button.rb', line 27 def when(event_name, &block) send(event_name).register(&block) end |