Created
July 26, 2016 11:17
-
-
Save alexandru-calinoiu/8442b2d916e38d8dfdbce4330e737cdf to your computer and use it in GitHub Desktop.
Some notes about observables based on a blog entry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'observer' | |
class Source | |
include Observable | |
def ping(int) | |
changed | |
notify_observers(int) | |
end | |
end | |
class Sink | |
def update(int) | |
puts int | |
end | |
end | |
class SnarkySink | |
def update(int) | |
fail 'I aim to misbehave' | |
end | |
end | |
source = Source.new | |
source.ping(3) | |
sink = Sink.new | |
source.add_observer(sink) | |
source.ping(7) | |
snarky_sink = SnarkySink.new | |
source.add_observer(snarky_sink) | |
source.ping(7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment