Sha256: d9ea5b83b67895cc4bd2f5d63beed46aa698f9e82b9efda60d29ac7bc9335592
Contents?: true
Size: 941 Bytes
Versions: 19
Compression:
Stored size: 941 Bytes
Contents
module WebSocket class Driver module EventEmitter def initialize @listeners = Hash.new { |h,k| h[k] = [] } end def add_listener(event, &listener) @listeners[event.to_s] << listener end def on(event, &listener) add_listener(event, &listener) end def remove_listener(event, &listener) @listeners[event.to_s].delete(listener) end def remove_all_listeners(event = nil) if event @listeners.delete(event.to_s) else @listeners.clear end end def emit(event, *args) @listeners[event.to_s].dup.each do |listener| listener.call(*args) end end def listener_count(event) return 0 unless @listeners.has_key?(event.to_s) @listeners[event.to_s].size end def listeners(event) @listeners[event.to_s] end end end end
Version data entries
19 entries across 19 versions & 2 rubygems