Class: Trooper::Arsenal
- Inherits:
-
Array
- Object
- Array
- Trooper::Arsenal
- Defined in:
- lib/trooper/arsenal.rb
Class Method Summary collapse
-
.actions ⇒ Object
Public: Storage for the defined actions.
-
.reset! ⇒ Object
Public: Clears the arsenals storage of all strategies and actions.
-
.strategies ⇒ Object
Public: Storage for the defined strategies.
Instance Method Summary collapse
-
#add(weapon) ⇒ Object
Public: Add a ‘weapon’ to the arsenal.
-
#clear! ⇒ Object
Public: Clears the arsenals storage array.
-
#find_by_name(name) ⇒ Object
(also: #[])
Public: Find an item in the arsenal.
-
#remove(name) ⇒ Object
Public: Removes a ‘weapon’ from the arsenal.
Class Method Details
.actions ⇒ Object
Public: Storage for the defined actions.
Examples
Arsenal.actions # => [<Action>, <Action>]
Returns the actions arsenal.
81 82 83 |
# File 'lib/trooper/arsenal.rb', line 81 def actions @actions ||= new end |
.reset! ⇒ Object
Public: Clears the arsenals storage of all strategies and actions.
Examples
Arsenal.reset! # => true
Returns true.
92 93 94 95 |
# File 'lib/trooper/arsenal.rb', line 92 def reset! @strategies, @actions = nil true end |
.strategies ⇒ Object
Public: Storage for the defined strategies.
Examples
Arsenal.strategies # => [<Strategy>, <Strategy>]
Returns the strategies arsenal.
70 71 72 |
# File 'lib/trooper/arsenal.rb', line 70 def strategies @strategies ||= new end |
Instance Method Details
#add(weapon) ⇒ Object
Public: Add a ‘weapon’ to the arsenal.
weapon - An object that responds to a name method e.g ‘weapon.name’ .
Examples
Arsenal.actions.add(<Action>) # => <Action>
Returns the weapon passed.
29 30 31 32 33 34 35 |
# File 'lib/trooper/arsenal.rb', line 29 def add(weapon) if weapon.ok? remove weapon.name self << weapon end weapon end |
#clear! ⇒ Object
Public: Clears the arsenals storage array.
Examples
Arsenal.strategies.clear! # => []
Returns an empty array.
57 58 59 |
# File 'lib/trooper/arsenal.rb', line 57 def clear! self.clear end |
#find_by_name(name) ⇒ Object Also known as: []
Public: Find an item in the arsenal.
name - The name of the weapon object, weapon object must respond to name.
Examples
Arsenal.strategies.find_by_name(:my_stratergy) # => <Strategy>
Arsenal.strategies[:my_stratergy] # => <Strategy>
Returns the duplicated String.
15 16 17 |
# File 'lib/trooper/arsenal.rb', line 15 def find_by_name(name) detect { |weapon| weapon.name == name } end |