Class: WrapperBased::Casting
- Inherits:
-
Module
- Object
- Module
- WrapperBased::Casting
show all
- Defined in:
- lib/wrapper_based/casting.rb
Defined Under Namespace
Classes: Director, Pool, Type
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Casting.
5
6
7
|
# File 'lib/wrapper_based/casting.rb', line 5
def initialize
include WrapperBased
end
|
Instance Method Details
#casts(role) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/wrapper_based/casting.rb', line 9
def casts(role)
role_writer = :"#{role}="
define_method(:"with_#{role}!") do |value|
send role_writer, yield(value)
self
end
private_reader role
private_writer role
end
|
#casts_as(role, &recast) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/wrapper_based/casting.rb', line 21
def casts_as(role, &recast)
role_player = :"@#{role}"
define_method(:"with_#{role}!") do |actor|
_components[role] = cast_as(role, actor, &recast)
instance_variable_set(role_player, actor)
self
end
private_reader role
private_writer role
end
|