lib/microevent.rb in microevent-1.0.2 vs lib/microevent.rb in microevent-1.1.0

- old
+ new

@@ -1,18 +1,16 @@ module MicroEvent - VERSION = "1.0.2".freeze + 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) - @_ ||= Hash.new{ |h,k| h[k] = [] } - fn ? @_[event].delete(fn) : @_.delete(event) || [] + fn ? @_ && @_[event].delete(fn) : @_ && @_.delete(event) || [] end def trigger(event, *args) - @_ ||= Hash.new{ |h,k| h[k] = [] } - !@_[event].dup.each{ |fn| instance_exec(*args, &fn) }.empty? + !!@_ && !@_[event].dup.each{ |fn| instance_exec(*args, &fn) }.empty? end end