I'm using a tool for finding code smells in code called reek and I have a problem with one called Control Parameter
def place_ship(ship, start_position, orientation)
@row = start_position[:row]
@column = start_position[:column]
ship.length.times do
if orientation == :vertical
vertical_place_ship(row,column,ship)
else
horizontal_place_ship(row,column,ship)
end
end
end
def vertical_place_ship(row,column,ship)
self.grid[row][column].ship = ship
self.grid[row][column].status = :occupied
@row += 1
end
def horizontal_place_ship(row,column,ship)
self.grid[row][column].ship = ship
self.grid[row][column].status = :occupied
@column += 1
end
warning's content: [
55]:ControlParameter: Board#place_ship is controlled by argument 'orientation
How do I fix this?
Regardless of the tool feedback, looking at your code, the only line that differ between the horizontal & vertical case is whether to increase @rows or @columns. An option could be:
I removed the two (identical) methods, and just used the ternary operator ('?') to increase the correct variable after placing each ship part.