Class: WrapperBased::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/wrapper_based/context.rb

Defined Under Namespace

Modules: TypeCasting Classes: Builder, Casting, CastingDirector

Constant Summary collapse

UnassignedRole =
Class.new(StandardError)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**where) ⇒ Context

Returns a new instance of Context.



3
4
5
6
# File 'lib/wrapper_based/context.rb', line 3

def initialize(**where)
  @casting_director = CastingDirector.new(self.class)
  where.each { |role, player| send :"#{role}=", player }
end

Class Method Details

.cast_as(role, actor) ⇒ Object



21
22
23
# File 'lib/wrapper_based/context.rb', line 21

def cast_as(role, actor)
  send(role).typecast(actor)
end

Instance Method Details

#[](*args, &block) ⇒ Object



12
13
14
# File 'lib/wrapper_based/context.rb', line 12

def [](*args, &block)
  call(*args, &block)
end

#to_procObject



8
9
10
# File 'lib/wrapper_based/context.rb', line 8

def to_proc
  method(:call).to_proc
end