aboutsummaryrefslogtreecommitdiffstats
path: root/lib/plum/event_emitter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/plum/event_emitter.rb')
-rw-r--r--lib/plum/event_emitter.rb10
1 files changed, 3 insertions, 7 deletions
diff --git a/lib/plum/event_emitter.rb b/lib/plum/event_emitter.rb
index 7bc9695..e0684dd 100644
--- a/lib/plum/event_emitter.rb
+++ b/lib/plum/event_emitter.rb
@@ -5,18 +5,14 @@ module Plum
# @param name [Symbol] The name of event.
# @yield Gives event-specific parameters.
def on(name, &blk)
- (callbacks[name] ||= []) << blk
+ @callbacks ||= {}
+ (@callbacks[name] ||= []) << blk
end
# Invokes an event and call handlers with args.
# @param name [Symbol] The identifier of event.
def callback(name, *args)
- (cbs = callbacks[name]) && cbs.each {|cb| cb.call(*args) }
- end
-
- private
- def callbacks
- @callbacks ||= {}
+ @callbacks&.[](name)&.each { |cb| cb.call(*args) }
end
end
end