Class: WrapperBased::Context::Casting
- Inherits:
-
Object
- Object
- WrapperBased::Context::Casting
- Defined in:
- lib/wrapper_based/context/casting.rb
Instance Attribute Summary collapse
-
#dci ⇒ Object
readonly
Returns the value of attribute dci.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #as(extention) ⇒ Object
- #cast_type(type) ⇒ Object
-
#initialize(name, dci) ⇒ Casting
constructor
A new instance of Casting.
- #typecast(actor) ⇒ Object
Constructor Details
#initialize(name, dci) ⇒ Casting
Returns a new instance of Casting.
7 8 9 10 11 |
# File 'lib/wrapper_based/context/casting.rb', line 7 def initialize(name, dci) @name = name.to_sym @casting = Set.new @dci = dci end |
Instance Attribute Details
#dci ⇒ Object (readonly)
Returns the value of attribute dci.
5 6 7 |
# File 'lib/wrapper_based/context/casting.rb', line 5 def dci @dci end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/wrapper_based/context/casting.rb', line 5 def name @name end |
Instance Method Details
#as(extention) ⇒ Object
13 14 15 16 |
# File 'lib/wrapper_based/context/casting.rb', line 13 def as(extention) @casting << extention self end |
#cast_type(type) ⇒ Object
18 19 20 |
# File 'lib/wrapper_based/context/casting.rb', line 18 def cast_type(type) @dci.wrapper_for type, *@casting end |
#typecast(actor) ⇒ Object
22 23 24 25 |
# File 'lib/wrapper_based/context/casting.rb', line 22 def typecast(actor) return actor if @casting.empty? cast_type(actor.class).new actor end |