HasGuardedHandlers

Parsed documentation:
View on GitHub
HasGuardedHandlers allows an object's API to provide flexible handler registration, storage and matching to arbitrary events.

HasGuardedHandlers is a module that should be mixed into some object which needs to emit events.

See the README for more usage info.

@author Ben Langfeld <ben@langfeld.me>

@example Simple usage

  require 'has_guarded_handlers'
  
  class A
    include HasGuardedHandlers
  end
  
  a = A.new
  a.register_handler :event do |event|
    puts "Handled the event #{event.inspect}"
  end
  
  a.trigger_handler :event, "Foo!"

@example Guarding event handlers

  require 'has_guarded_handlers'
  
  class A
    include HasGuardedHandlers
  end
  
  a = A.new
  a.register_handler :event, :type => :foo do |event|
    puts "Handled the event of type #{event.type} with value #{event.value}"
  end
  
  Event = Class.new Struct.new(:type, :value)
  
  a.trigger_handler :event, Event.new(:foo, 'bar')
No suggestions.
Please help! Open an issue on GitHub if this assessment is incorrect.