You need to always specify a list of arguments.
class EventManager def initialize @callbacks = Hash(String, Array(String ->)).new {|h, k| h[k] = [] of String -> } end def add(event, &callback : String ->) @callbacks[event] << callback end def fire(event, argument : String) @callbacks[event].each &.call(argument) end end callbacks = EventManager.new callbacks.add("foo") do |argument| puts "Got #{argument}" end callbacks.add("bar") do puts "I was called" end callbacks.fire "foo", "Ping" callbacks.fire "bar", "Pong"
source share