Class Rubygame::EventTriggers::OrTrigger
In: lib/rubygame/event_triggers.rb
Parent: Object

OrTrigger is an event trigger which contains one or more other triggers, and fires when an event matches one or more of its triggers.

Contrast with AndTrigger.


match?   new  

Public Class methods

Initialize a new instance of OrTrigger, containing the given triggers.

*triggers:The triggers to contain. (Array of triggers, required)


  is_red = :color => :red )
  is_blue = :color => :blue )

  # Matches only an event which has EITHER:
  #  1. #color == :red, OR
  #  2. #color == :blue
  is_red_or_blue = is_red, is_blue )

  # More complex example with nested logic triggers:

  changed = ColorChanged )

  changed_to_red_or_blue = changed, is_red_or_blue )


# File lib/rubygame/event_triggers.rb, line 157
        def initialize( *triggers )
                @triggers = triggers

Public Instance methods

Returns true if the event matches one or more of the triggers that the OrTrigger contains.


# File lib/rubygame/event_triggers.rb, line 164
        def match?( event )
                @triggers.any? { |trigger| trigger.match? event }