Class: Eventful::Observer

Inherits:
Methodphitamine::It
  • Object
show all
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

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