Sha256: 1b886cff653a6d20d993e1e4c76bfca83a0c6764bf63ab495b53f05b380d0f6e
Contents?: true
Size: 1.03 KB
Versions: 1
Compression:
Stored size: 1.03 KB
Contents
# Syntactic sugar for adding a listener. Use include or extend to # add listen/subscribe behaviour to your class instance # or class body. # class MyListener # include Flirt::Listener # # def initialize # subscribe_to :picked, with: :picked_callback # # or the alias # listen_to :picked, with: :picked_callback # end # # def picked_callback(event_data) # puts "The #{event_data[:fruit]} has been picked" # end # end # # or: # # class MyListener # extend Flirt::Listener # # subscribe_to :picked, with: :picked_callback # # or the alias # listen_to :picked, with: :picked_callback # # def self.picked_callback(event_data) # puts "The #{event_data[:fruit]} has been picked" # end # end # module Flirt module Listener def subscribe_to(event_name, opts = {}) Flirt.subscribe self, event_name, opts end def unsubscribe_from(event_name, opts = {}) Flirt.unsubscribe self, event_name, opts end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
flirt-0.0.4 | lib/flirt/listener.rb |