Class: BattleBoats::Ship
- Inherits:
-
Object
- Object
- BattleBoats::Ship
- Defined in:
- lib/battle_boats/ship.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #hit ⇒ Object
- #hit_count ⇒ Object
-
#initialize(name:, length:, symbol: "O") ⇒ Ship
constructor
A new instance of Ship.
- #sunk? ⇒ Boolean
Constructor Details
#initialize(name:, length:, symbol: "O") ⇒ Ship
Returns a new instance of Ship.
8 9 10 11 12 13 |
# File 'lib/battle_boats/ship.rb', line 8 def initialize(name:, length:, symbol: "O") @name = name @length = length @symbol = symbol.red @hits = 0 end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
6 7 8 |
# File 'lib/battle_boats/ship.rb', line 6 def length @length end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/battle_boats/ship.rb', line 6 def name @name end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
6 7 8 |
# File 'lib/battle_boats/ship.rb', line 6 def symbol @symbol end |
Instance Method Details
#empty? ⇒ Boolean
15 16 17 |
# File 'lib/battle_boats/ship.rb', line 15 def empty? false end |
#hit ⇒ Object
23 24 25 |
# File 'lib/battle_boats/ship.rb', line 23 def hit @hits += 1 end |
#hit_count ⇒ Object
19 20 21 |
# File 'lib/battle_boats/ship.rb', line 19 def hit_count @hits end |
#sunk? ⇒ Boolean
27 28 29 |
# File 'lib/battle_boats/ship.rb', line 27 def sunk? hit_count == length end |