Sha256: 4ab7e89621c771537c0c07cc0a3fff96c401ca7f0696b03c69f794d64f556e65
Contents?: true
Size: 537 Bytes
Versions: 1
Compression:
Stored size: 537 Bytes
Contents
module EventEmitter def self.included(klass) klass.extend ClassMethods klass.__send__ :include, InstanceMethods end module ClassMethods end module InstanceMethods def events @events ||= [] end def on(type, &block) raise ArgumentError, 'listener block not given' unless block_given? events << {:type => type.to_sym, :listener => block} end def emit(type, data) events.each do |e| e[:listener].call data if e[:type] == type.to_sym end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
event_emitter-0.0.1 | lib/event_emitter/emitter.rb |