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.

Methods

match?   new  

Public Class methods

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 )

[Source]

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

Public Instance methods

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

[Source]

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

[Validate]