Class: BattleBoats::Ship

Inherits:
Object
  • Object
show all
Defined in:
lib/battle_boats/ship.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#lengthObject (readonly)

Returns the value of attribute length


3
4
5
# File 'lib/battle_boats/ship.rb', line 3

def length
  @length
end

#nameObject (readonly)

Returns the value of attribute name


3
4
5
# File 'lib/battle_boats/ship.rb', line 3

def name
  @name
end

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

Returns:

  • (Boolean)

12
13
14
# File 'lib/battle_boats/ship.rb', line 12

def empty?
  false
end

#hitObject


16
17
18
# File 'lib/battle_boats/ship.rb', line 16

def hit
  @hits += 1
end

#sunk?Boolean

Returns:

  • (Boolean)

20
21
22
# File 'lib/battle_boats/ship.rb', line 20

def sunk?
  @hits == length
end