1

I'm getting below error in my Robot class:

Commands tests @robot.placed at least 4 times (RepeatedConditional)

This is the problematic code that's causing it:

def move
  @robot.move_forward if @robot.placed
end

def left
  @robot.left if @robot.placed
end

def right
  @robot.right if @robot.placed
end

def report
  puts @robot.report_current_position if @robot.placed
end

How would we re-organise this to avoid this warning?

Zippie
  • 6,018
  • 6
  • 31
  • 46
Passionate Engineer
  • 10,034
  • 26
  • 96
  • 168

1 Answers1

0

you should refactor it out in a single method

def robot_placed?
  @robot.placed
end

and then call the method in your methods

def right
  @robot.right if robot_placed?
end

And put robot_placed? in the private section of your class ;-)

awenkhh
  • 5,811
  • 1
  • 21
  • 24