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
-
#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.
5 6 7 8 9 10 |
# File 'lib/battle_boats/ship.rb', line 5 def initialize(name:, length:, symbol: "O") @name = name @length = length @symbol = symbol @hits = 0 end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
3 4 5 |
# File 'lib/battle_boats/ship.rb', line 3 def length @length end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/battle_boats/ship.rb', line 3 def name @name end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
3 4 5 |
# File 'lib/battle_boats/ship.rb', line 3 def symbol @symbol end |
Instance Method Details
#empty? ⇒ Boolean
12 13 14 |
# File 'lib/battle_boats/ship.rb', line 12 def empty? false end |
#hit ⇒ Object
16 17 18 |
# File 'lib/battle_boats/ship.rb', line 16 def hit @hits += 1 end |
#sunk? ⇒ Boolean
20 21 22 |
# File 'lib/battle_boats/ship.rb', line 20 def sunk? @hits == length end |