Class Rubygame::EventActions::BlockAction
In: lib/rubygame/event_actions.rb
Parent: Object

BlockAction is an event action used with EventHook. BlockAction takes a code block at initialization. When the action is performed, it executes the block, passing in the EventHook#owner and the event that is being handled as the two parameters to the block.


  hit_by_missile = MissileCollisionEvent )

  take_damage = { |owner, event| -= event.damage_amount

  hook = :owner   => player_ship,
                        :trigger => hit_by_missile,
                        :action  => take_damage )

NOTE: It is also possible to pass a Proc or detached Method as the block, using the standard Ruby syntax for that:

  # Using a pre-built Proc.

  my_proc = { |owner, event| do_something() } &my_proc )

  # Using a detached method.

  def a_method( owner, event )

  detached_method = method(:a_method) &detached_method )


new   perform  

Public Class methods

Create a new BlockAction using the given code block.

&block:the code block to execute. Should take two parameters, owner and event. (Proc, required)
May raise:ArgumentError, if no block is provided.


# File lib/rubygame/event_actions.rb, line 100
        def initialize( &block )
                raise ArgumentError, "BlockAction needs a block" unless block_given?
                @block = block

Public Instance methods

Execute the code block, passing in owner and event as the two parameters to the block. This is automatically called by EventHook when an event matches the trigger. You should usually not call it in your own code.

owner:the owner of the EventHook, or nil if there is none. (Object, required)
event:the event that matched the trigger. (Object, required)


# File lib/rubygame/event_actions.rb, line 114
        def perform( owner, event )
       owner, event )