From 6c0db225048a8dfc28a445c1da57e415edfc8c4a Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Mon, 30 Oct 2023 16:30:04 +0000 Subject: [PATCH] Moved the logic into the forwards method. --- lib/mars_rover.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/mars_rover.rb b/lib/mars_rover.rb index 979d005..9fcd4fb 100644 --- a/lib/mars_rover.rb +++ b/lib/mars_rover.rb @@ -13,12 +13,7 @@ def execute(commands) when 'b' backwards(location) when 'f' - new_location = forwards(location) - if @map.located_at_north_pole? new_location.coordinates - Location.new(coordinates: Coordinates.new(x: new_location.coordinates.x + 18, y: 8), direction: 'S') - else - new_location - end + forwards(location) when 'l' location.rotate_left when 'r' @@ -44,7 +39,12 @@ def inspect private def forwards(current_location) - @map.next_location_forwards(location: current_location) + new_location = @map.next_location_forwards(location: current_location) + if @map.located_at_north_pole? new_location.coordinates + Location.new(coordinates: Coordinates.new(x: new_location.coordinates.x + 18, y: 8), direction: 'S') + else + new_location + end end def backwards(current_location)