Observe: A simple interface for adding observers to any class.
Observe provides a simple interface for adding observers to any class. Love to hear your thoughts!
Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!
Observe provides a simple interface for adding observers to any class. Love to hear your thoughts!
Comments
Your code is the same as builtin Observable http://ruby-doc.org/stdlib-1.9.2/libdoc/observer/rdoc/Observable.html
It is not the same code, I wrote it myself. It was inspired by Observable, but if you read the README I go through the differences.
I’ll list some here:
Observers belong to ‘groups’
There is no ‘changed’ method. A method required to ‘flip state’ by the Observable module to notify observers.
Observable introduces 7 methods, and 2 instance variables. Observe introduces 4, one instance variable.
The interface is extremely similar, but the implementation and concept(groups, no changed methods) differs.
I go through all that in the README, though (or I thought I did).
I have no problem with ‘Observable’ in the standard library, but the enforcement of calling ‘changed’ was a show stopper for me, and so ‘Observe’ was born.
Groups were a later thought that I found to be useful.
I forgot: An observer is any object that responds to
#call
in ‘Observe’.In ‘Observable’ (standard library), an observer is any object that responds to
#update
, although it is configurable.Post a comment