문제

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?

도움이 되었습니까?

해결책

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 ;-)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top