Sha256: cb59d8e1f0826ac20f37af8d2e409053bbe740a2e0f4524125cfe8a9e9adf5de

Contents?: true

Size: 415 Bytes

Versions: 1

Compression:

Stored size: 415 Bytes

Contents

# frozen_string_literal: true

module MicroEvent
  VERSION = "1.1.1"

  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.1 lib/microevent.rb