Class: DCI::Context
Class Method Summary collapse
-
.[](*args) ⇒ Object
A short way for ContextSubclass.new(players_and_extra_args).run(extra_args).
-
.inherited(subklass) ⇒ Object
Every subclass of Context has is own class and instance method roles defined.
- .method_added(methodname) ⇒ Object
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Context
constructor
Instances of a defined subclass of Context are initialized checking first that all subclass defined roles are provided in the creation invocation raising an error if any of them is missing.
Constructor Details
#initialize(args = {}) ⇒ Context
Instances of a defined subclass of Context are initialized checking first that all subclass defined roles are provided in the creation invocation raising an error if any of them is missing. Once the previous check is met, every object playing in the context instance is associated to the stated role. Non players args are associated to instance_variables and readers defined.
117 118 119 120 121 122 |
# File 'lib/drsi/dci/context.rb', line 117 def initialize(args={}) check_all_roles_provided_in!(args) players, noplayers = args.partition {|key, *| roles.has_key?(key)}.map {|group| Hash[*group.flatten(1)]} @_players = players @settings = noplayers end |
Class Method Details
.[](*args) ⇒ Object
A short way for ContextSubclass.new(players_and_extra_args).run(extra_args)
22 23 24 |
# File 'lib/drsi/dci/context.rb', line 22 def [](*args) new(*args).run end |
.inherited(subklass) ⇒ Object
Every subclass of Context has is own class and instance method roles defined. The instance method delegates value to the class.
11 12 13 14 15 16 17 18 19 |
# File 'lib/drsi/dci/context.rb', line 11 def inherited(subklass) subklass.class_eval do @roles ||= {} def self.roles; @roles end def roles; self.class.roles end private :roles assign_unplay_roles_within_instance_methods! end end |
.method_added(methodname) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/drsi/dci/context.rb', line 85 def self.method_added(methodname) if not @context_internals and public_method_defined?(methodname) @context_internals = true assign_unplay_roles_within_instance_method!(methodname) @context_internals = false end end |