Sha256: 69bb766354693322a459bffe0c154650c5d1940aa00a2204242762044f6964c3

Contents?: true

Size: 577 Bytes

Versions: 1

Compression:

Stored size: 577 Bytes

Contents

# frozen_string_literal: true

module Voltage
  class Listener
    def initialize(context, type, event, &block)
      @context = context
      @type = type
      @event = event
      @block = block
      @event_method = :"#{@type}_#{@event}"
    end

    def method_missing(method_name, *args)
      return super unless respond_to_missing?(method_name, false)

      @block.call(*args)
    end

    def to_s
      "<#{self.class} event: #{@event_method}>"
    end

    def respond_to_missing?(method_name, _include_private)
      method_name == @event_method
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
voltage-0.1.0 lib/voltage/listener.rb