Sha256: 248bcf0d52b0b953c35160db2cbaf73debc1f4839bb8739edc0a1e691d5f0587
Contents?: true
Size: 686 Bytes
Versions: 1
Compression:
Stored size: 686 Bytes
Contents
require 'moosex' require 'moosex/event' class EventHandler include MooseX include MooseX::Event def has_events [ :pinged, :ponged ] end end class EventProcessor include MooseX has event_handler: { is: :ro, isa: EventHandler, default: lambda{ EventHandler.new }, handles: { ping: { emit: :pinged }, pong: { emit: :ponged }, on_ping: { on: :pinged }, on_pong: { on: :ponged }, }, } end ep = EventProcessor.new() ep.on_ping do |x| puts "receive ping!" end ep.on_pong do |obj, message| puts "receive pong with #{message}!" end ep.ping # will print "receive ping!" ep.pong 1 # will print "receive pong!"
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
moosex-0.0.16 | samples/events.rb |