Skip to content

Instantly share code, notes, and snippets.

@alexandru-calinoiu
Created July 26, 2016 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexandru-calinoiu/8442b2d916e38d8dfdbce4330e737cdf to your computer and use it in GitHub Desktop.
Save alexandru-calinoiu/8442b2d916e38d8dfdbce4330e737cdf to your computer and use it in GitHub Desktop.
Some notes about observables based on a blog entry
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