Class: Rubygame::EventTriggers::BlockTrigger

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygame/event_triggers.rb

Overview

BlockTrigger is an event trigger which calls a block to check events. The trigger fires if the block returns true when called with the event as the only parameter.

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ BlockTrigger

Initialize a new instance of BlockTrigger with the given block. The block should take only 1 parameter, the event, and return true for matching events.

&block

The block to pass events to. (Proc, required)

Raises:

  • (ArgumentError)


224
225
226
227
# File 'lib/rubygame/event_triggers.rb', line 224

def initialize( &block )
	raise ArgumentError, "BlockTrigger needs a block" unless block_given?
	@block = block
end

Instance Method Details

#match?(event) ⇒ Boolean

Returns true if the block returns true when called with the event as the only parameter.

Returns:

  • (Boolean)


232
233
234
# File 'lib/rubygame/event_triggers.rb', line 232

def match?( event )
	@block.call( event ) == true
end