Sha256: 25b0c1fee67c5977ba20f86b175eca40a7ae51bc8576157db5ec17dc78df2144

Contents?: true

Size: 449 Bytes

Versions: 1

Compression:

Stored size: 449 Bytes

Contents

module MicroEvent
  VERSION = "1.0.2".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) || []
  end

  def trigger(event, *args)
    @_ ||= Hash.new{ |h,k| h[k] = [] }
    !@_[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.0.2 lib/microevent.rb