Class: Degica::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/degica/action.rb

Overview

Actionable objects return actions. These actions can be invoked in the game REPL and delegate function calls to a @target ruby object method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name_, target_) ⇒ Action

Returns a new instance of Action.



8
9
10
11
# File 'lib/degica/action.rb', line 8

def initialize(name_, target_)
  @name = name_
  @target = target_
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/degica/action.rb', line 6

def name
  @name
end

#targetObject (readonly)

Returns the value of attribute target.



6
7
8
# File 'lib/degica/action.rb', line 6

def target
  @target
end

Instance Method Details

#do(*args) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/degica/action.rb', line 13

def do(*args)
  if @target.respond_to?(name)
    @target.send(name, *args)
  else
    @target
  end
end

#inspectObject



21
22
23
# File 'lib/degica/action.rb', line 21

def inspect
  "#{@name}"
end