Sha256: 999efe408430107377db021d9390344ca212a9bc0d99630776e040de011e21d3

Contents?: true

Size: 573 Bytes

Versions: 6

Compression:

Stored size: 573 Bytes

Contents

module BubbleWrap
  module Reactor
    # A simple mixin that adds events to your object.
    module Eventable

      # When `event` is triggered the block will execute
      # and be passed the arguments that are passed to
      # `trigger`.
      def on(event, &blk)
        @events ||= Hash.new { |h,k| h[k] = [] }
        @events[event].push blk
      end

      # Trigger an event
      def trigger(event, *args)
        @events ||= Hash.new { |h,k| h[k] = [] }
        @events[event].map do |event|
          event.call(*args)
        end
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bubble-wrap-1.1.5 motion/reactor/eventable.rb
bubble-wrap-1.1.4 motion/reactor/eventable.rb
bubble-wrap-1.1.3 motion/reactor/eventable.rb
bubble-wrap-1.1.2 motion/reactor/eventable.rb
bubble-wrap-1.1.1 motion/reactor/eventable.rb
bubble-wrap-1.1.0 motion/reactor/eventable.rb