class Battleships::Ship

Constants

SIZES

Attributes

size[R]
type[R]

Public Class Methods

aircraft_carrier() click to toggle source
# File lib/battleships/ship.rb, line 43
def self.aircraft_carrier
  Ship.new(:aircraft_carrier)
end
battleship() click to toggle source
# File lib/battleships/ship.rb, line 39
def self.battleship
  Ship.new(:battleship)
end
cruiser() click to toggle source
# File lib/battleships/ship.rb, line 35
def self.cruiser
  Ship.new(:cruiser)
end
destroyer() click to toggle source
# File lib/battleships/ship.rb, line 31
def self.destroyer
  Ship.new(:destroyer)
end
new(type) click to toggle source
# File lib/battleships/ship.rb, line 13
def initialize type
  @type = type.to_sym
  @size = SIZES[@type]
  @hits = 0
end
submarine() click to toggle source
# File lib/battleships/ship.rb, line 27
def self.submarine
  Ship.new(:submarine)
end

Public Instance Methods

hit() click to toggle source
# File lib/battleships/ship.rb, line 19
def hit
  @hits += 1
end
sunk?() click to toggle source
# File lib/battleships/ship.rb, line 23
def sunk?
  @hits >= size
end