Class: DCI::Role
- Inherits:
-
Object
- Object
- DCI::Role
- Extended by:
- Forwardable
- Defined in:
- lib/dci-ruby/dci/role.rb
Class Method Summary collapse
-
.add_role_reader_for!(rolekey) ⇒ Object
Defines a new reader instance method for a context mate role, delegating it to the context object.
- .delegate_to_player(player_methodname, role_method_name = player_methodname) ⇒ Object
- .delegates_to_player(*methodnames) ⇒ Object
-
.new(*args, &block) ⇒ Object
Make this class abstract: will not allow create instances.
- .private_delegate_to_player(player_methodname, role_method_name = player_methodname) ⇒ Object
- .private_delegates_to_player(*methodnames) ⇒ Object
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Role
constructor
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.
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 in the given context
44 45 46 47 |
# File 'lib/dci-ruby/dci/role.rb', line 44 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.
32 33 34 35 36 |
# File 'lib/dci-ruby/dci/role.rb', line 32 def add_role_reader_for!(rolekey) return if private_method_defined?(rolekey) define_method(rolekey) {@context.send(rolekey)} private rolekey end |
.delegate_to_player(player_methodname, role_method_name = player_methodname) ⇒ Object
14 15 16 |
# File 'lib/dci-ruby/dci/role.rb', line 14 def delegate_to_player(player_methodname, role_method_name = player_methodname) class_eval("def #{role_method_name}(*args, &block); player.send(:#{player_methodname}, *args, &block) end") end |
.delegates_to_player(*methodnames) ⇒ Object
23 24 25 |
# File 'lib/dci-ruby/dci/role.rb', line 23 def delegates_to_player(*methodnames) methodnames.each {|methodname| delegate_to_player(methodname)} end |
.new(*args, &block) ⇒ Object
Make this class abstract: will not allow create instances.
9 10 11 12 |
# File 'lib/dci-ruby/dci/role.rb', line 9 def new(*args, &block) raise 'This class is meant to be abstract and not instantiable' if self == DCI::Role super end |
.private_delegate_to_player(player_methodname, role_method_name = player_methodname) ⇒ Object
18 19 20 21 |
# File 'lib/dci-ruby/dci/role.rb', line 18 def private_delegate_to_player(player_methodname, role_method_name = player_methodname) delegate_to_player(player_methodname, role_method_name) private role_method_name end |
.private_delegates_to_player(*methodnames) ⇒ Object
27 28 29 |
# File 'lib/dci-ruby/dci/role.rb', line 27 def private_delegates_to_player(*methodnames) methodnames.each {|methodname| private_delegate_to_player(methodname)} end |