Skip to content

Commit

Permalink
Refactor/Extract constant, made it clear that turn right is
Browse files Browse the repository at this point in the history
the inverse of turn left.
  • Loading branch information
hemalvarambhia committed Oct 30, 2023
1 parent 4fba052 commit 575548d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class Location
}.freeze
private_constant :TURN_LEFT

TURN_RIGHT = TURN_LEFT.invert
private_constant :TURN_RIGHT

def initialize(coordinates:, direction:)
@coordinates = coordinates
@direction = direction
Expand All @@ -24,7 +27,7 @@ def rotate_left
def rotate_right
Location.new(
coordinates: coordinates,
direction: TURN_LEFT.invert[direction]
direction: TURN_RIGHT[direction]
)
end

Expand Down

0 comments on commit 575548d

Please sign in to comment.