After the discussion about using observer on another thread I wrote a little code to let me use blocks/closures. Was wondering if anybody else had done this and had an insight on its actual application?
obj.add_observer(:type_selected) do |data| ### do something with data variable end
Basically the code block is doing the observing and will be executed. :type_selected is the filter so it doesn't receive all types of data. Seems interesting, although I think it may just have the same (or even less) usefulness. (On a side note, though, it isn't really much different except I can attached loaded script directly to an event.)
edit: There's a standard library implementing the pattern in Ruby, but it doesn't allow blocks as observers.