module RETerm::EventDispatcher
Helper mixin defining methods to register event handlers and dispatch events. Events are simply composed parameters which are passed to the callback blocks when dispatched
Public Instance Methods
dispatch(e, h={})
click to toggle source
# File lib/reterm/mixins/event_dispatcher.rb, line 7 def dispatch(e, h={}) @event_handlers ||= {} @event_handlers[e].each { |eh| eh.call h } if @event_handlers.key?(e) nil # return last handler return value or perhaps all ? end
handle(e, &bl)
click to toggle source
# File lib/reterm/mixins/event_dispatcher.rb, line 16 def handle(e, &bl) @event_handlers ||= {} @event_handlers[e] ||= [] @event_handlers[e] << bl end