Class: Eventful::Observer
- Inherits:
-
Methodphitamine::It
- Object
- Methodphitamine::It
- Eventful::Observer
- Defined in:
- lib/eventful.rb
Overview
The Observer
class is used to wrap blocks in an object that implements update
, so it can be used with Observable
. It extends Methodphitamine::It
, meaning it can store any methods called on it and replay them later on any object. This is used to implement blockless event handlers.
Instance Method Summary collapse
-
#initialize(&block) ⇒ Observer
constructor
Initalize using a block.
-
#update(*args) ⇒ Object
Called by the observed object inside
Observable
to publish events.
Constructor Details
#initialize(&block) ⇒ Observer
Initalize using a block. The block will be called when the observed object sends notifications.
17 18 19 20 |
# File 'lib/eventful.rb', line 17 def initialize(&block) super() @block = block end |
Instance Method Details
#update(*args) ⇒ Object
Called by the observed object inside Observable
to publish events.
23 24 25 |
# File 'lib/eventful.rb', line 23 def update(*args) @block.call(*args) end |