Class: WrapperBased::Casting::Type
- Inherits:
-
Object
- Object
- WrapperBased::Casting::Type
- Defined in:
- lib/wrapper_based/casting/type.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #[](*where) ⇒ Object
- #cast_type(type) ⇒ Object
- #has(talent) ⇒ Object
-
#initialize(name, talent_pool) ⇒ Type
constructor
A new instance of Type.
- #typecast(actor) ⇒ Object
Constructor Details
#initialize(name, talent_pool) ⇒ Type
Returns a new instance of Type.
7 8 9 10 11 |
# File 'lib/wrapper_based/casting/type.rb', line 7 def initialize(name, talent_pool) @name = name.to_sym @talents = Set.new @lookup = talent_pool end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/wrapper_based/casting/type.rb', line 5 def name @name end |
Instance Method Details
#[](*where) ⇒ Object
18 19 20 |
# File 'lib/wrapper_based/casting/type.rb', line 18 def [](*where) @lookup[where] end |
#cast_type(type) ⇒ Object
22 23 24 |
# File 'lib/wrapper_based/casting/type.rb', line 22 def cast_type(type) self[type, *@talents] end |
#has(talent) ⇒ Object
13 14 15 16 |
# File 'lib/wrapper_based/casting/type.rb', line 13 def has(talent) @talents << talent self end |
#typecast(actor) ⇒ Object
26 27 28 29 |
# File 'lib/wrapper_based/casting/type.rb', line 26 def typecast(actor) return actor if @talents.empty? cast_type(actor.class).new actor end |