Skip to content
Permalink
master
Go to file
 
 
Cannot retrieve contributors at this time
16 lines (13 sloc) 391 Bytes
module MicroEvent
VERSION = "1.1.0".freeze
def bind(event, &fn)
@_ ||= Hash.new{ |h,k| h[k] = [] }
fn ? @_[event] << fn : raise(ArgumentError, "no block given")
end
def unbind(event, &fn)
fn ? @_ && @_[event].delete(fn) : @_ && @_.delete(event) || []
end
def trigger(event, *args)
!!@_ && !@_[event].dup.each{ |fn| instance_exec(*args, &fn) }.empty?
end
end
You can’t perform that action at this time.