Sha256: 61d9471208e3e6ddcac373f87d77e7354e4e73c14edd54d938111995cf7486ab

Contents?: true

Size: 391 Bytes

Versions: 1

Compression:

Stored size: 391 Bytes

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
microevent-1.1.0 lib/microevent.rb