Class: DCI::Role

Inherits:
Object
  • Object
show all
Defined in:
lib/dci-ruby/dci/role.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Role

Opts:

player         => the object to adquire this role,
context        => the context instance in which this role instance will play
role_mate_keys => list of keys of the rest of roles playing in the given context


26
27
28
29
# File 'lib/dci-ruby/dci/role.rb', line 26

def initialize(opts={})
  @player  = opts[:player]
  @context = opts[:context]
end

Class Method Details

.add_role_reader_for!(rolekey) ⇒ Object

Defines a new reader instance method for a context mate role, delegating it to the context object.



14
15
16
17
18
# File 'lib/dci-ruby/dci/role.rb', line 14

def add_role_reader_for!(rolekey)
  return if private_method_defined?(rolekey)
  define_method(rolekey) {@context.send(rolekey)}
  private rolekey
end

.new(*args, &block) ⇒ Object

Make this class abstract: will not allow create instances.



8
9
10
11
# File 'lib/dci-ruby/dci/role.rb', line 8

def new(*args, &block)
  raise 'This class is meant to be abstract and not instantiable' if self == DCI::Role
  super
end