2013-08-28 25 views
1

我收到以下錯誤在我的機器人類:Ruby的臭佬質量檢查

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

這是有問題的代碼,導致了它:

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 

如何將我們重新組織該避免這個警告?

回答

1

你應該重構它在一個單一的方法

def robot_placed? 
    @robot.placed 
end 

,然後調用方法在你的方法

def right 
    @robot.right if robot_placed? 
end 

,並把robot_placed?在你班的私人部分;-)