MethodAction is an event action used with EventHook. MethodAction takes a symbol giving the name of a method. When it is performed, it calls that method on the owner, passing it the event that triggered the hook.
Example:
class Player def aim_at( event ) self.crosshair_pos = event.pos end end player1 = Player.new EventHook.new( :owner => player1, :trigger => MouseMoveTrigger.new(), :action => MethodAction.new( :aim_at ) )
Create a new MethodAction using the given method name.
method_name |
the method to call when performing. (Symbol, required) |
# File lib/rubygame/event_actions.rb, line 146 def initialize( method_name ) @method_name = method_name end
Call the method of the owner represented by @method_name, passing in the event as the only argument.
If that causes ArgumentError (e.g. because the method doesn't take an argument), calls again without any arguments.
If that also fails, this method re-raises the original error.
# File lib/rubygame/event_actions.rb, line 159 def perform( owner, event ) owner.method(@method_name).call( event ) rescue ArgumentError => s begin # Oops! Try again, without any argument. owner.method(@method_name).call() rescue ArgumentError # That didn't work either. Raise the original error. raise s end end
Generated with the Darkfish Rdoc Generator 2.