lib/ably/modules/event_emitter.rb in ably-0.1.6 vs lib/ably/modules/event_emitter.rb in ably-0.2.0
- old
+ new
@@ -40,22 +40,22 @@
# On receiving an event matching the event_name, call the provided block
#
# @param [Array<String>] event_names event name
#
- # @return <void>
+ # @return [void]
def on(*event_names, &block)
event_names.each do |event_name|
callbacks[callbacks_event_coerced(event_name)] << proc_for_block(block)
end
end
# On receiving an event maching the event_name, call the provided block only once and remove the registered callback
#
# @param [Array<String>] event_names event name
#
- # @return <void>
+ # @return [void]
def once(*event_names, &block)
event_names.each do |event_name|
callbacks[callbacks_event_coerced(event_name)] << proc_for_block(block, delete_once_run: true)
end
end
@@ -70,12 +70,18 @@
# If a block is provided, only callbacks matching that block signature will be removed.
# If block is not provided, all callbacks matching the event_name will be removed.
#
# @param [Array<String>] event_names event name
#
- # @return <void>
+ # @return [void]
def off(*event_names, &block)
- event_names.each do |event_name|
+ keys = if event_names.empty?
+ callbacks.keys
+ else
+ event_names
+ end
+
+ keys.each do |event_name|
if block_given?
callbacks[callbacks_event_coerced(event_name)].delete_if { |proc_hash| proc_hash[:block] == block }
else
callbacks[callbacks_event_coerced(event_name)].clear
end