class Rubygame::EventTriggers::OrTrigger

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.

Public Class Methods

new( *triggers ) click to toggle source

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

*triggers

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

Example:

is_red = AttrTrigger.new( :color => :red )
is_blue = AttrTrigger.new( :color => :blue )

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

# More complex example with nested logic triggers:

changed = InstanceOfTrigger.new( ColorChanged )

changed_to_red_or_blue = 
  AndTrigger.new( changed, is_red_or_blue )
# File lib/rubygame/event_triggers.rb, line 157
def initialize( *triggers )
        @triggers = triggers
end

Public Instance Methods

match?( event ) click to toggle source

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 }
end