Class: WrapperBased::Casting::Type

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (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