Module: Eventful::ObservableWithBlocks
Overview
Extends the Observable
module and allows it to accept blocks as observers. This is a distinct module because I often want to do this without using named events.
Instance Method Summary collapse
-
#add_observer(*args, &block) ⇒ Object
Adds an observer to the object.
Instance Method Details
#add_observer(*args, &block) ⇒ Object
Adds an observer to the object. The observer may be an object implementing update
, or a block that will be called when the object notifies observers. If a block is passed, we return the wrapping Observer
object so it can removed using delete_observer
.
46 47 48 49 50 51 |
# File 'lib/eventful.rb', line 46 def add_observer(*args, &block) return super unless block_given? observer = Observer.new(&block) add_observer(observer) observer end |