From ae2e14fd5b02bb495be0a270aae7235a14ba67fe Mon Sep 17 00:00:00 2001 From: mo k Date: Sun, 12 Feb 2012 14:30:03 -0700 Subject: remove Direction class. --- lib/rover.rb | 19 ++++++------------- spec/rover_specs.rb | 3 ++- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/rover.rb b/lib/rover.rb index 90d7757..8b992e9 100644 --- a/lib/rover.rb +++ b/lib/rover.rb @@ -1,11 +1,11 @@ class Rover attr_reader :location def initialize(heading, coordinates) - @heading = Direction.find(heading) + @heading = heading @location = coordinates end def heading - @heading.direction + @heading.to_sym end def turn_right @heading = @heading.turn_right @@ -19,7 +19,7 @@ class Rover end class North - def direction + def to_sym :north end def turn_right @@ -33,7 +33,7 @@ class North end end class East - def direction + def to_sym :east end def turn_right @@ -47,7 +47,7 @@ class East end end class West - def direction + def to_sym :west end def turn_right @@ -61,7 +61,7 @@ class West end end class South - def direction + def to_sym :south end def turn_right @@ -74,10 +74,3 @@ class South current_location[:y] = current_location[:y]-1 end end - -class Direction - @@directions = {:north => North.new, :east => East.new, :west => West.new, :south => South.new} - def self.find(heading) - @@directions[heading] - end -end diff --git a/spec/rover_specs.rb b/spec/rover_specs.rb index a54e2c2..9dc73d0 100644 --- a/spec/rover_specs.rb +++ b/spec/rover_specs.rb @@ -2,7 +2,8 @@ require 'rover' describe Rover do def create_sut(heading, x = 0, y = 0) - Rover.new heading,{ :x =>x,:y => y } + directions = {:north => North.new, :east => East.new, :west => West.new, :south => South.new} + Rover.new directions[heading],{ :x =>x,:y => y } end describe "when facing north" do -- cgit v1.2.3