Commit a65ecff

mo k <mo@mokhan.ca>
2012-11-07 04:25:32
remove turn_right and turn_left methods.
1 parent e2d6573
lib/east.rb
@@ -1,12 +1,6 @@
 class East
-  def turn_right
-    South.new
-  end
-  def turn_left
-    North.new
-  end
   def rotate(degrees)
-    degrees > 0 ? turn_right : turn_left
+    degrees > 0 ? South.new : North.new
   end
   def forward(location, plateau)
     plateau.increment(:x, location)
lib/north.rb
@@ -1,12 +1,6 @@
 class North
-  def turn_right
-    East.new
-  end
-  def turn_left
-    West.new
-  end
   def rotate(degrees)
-    degrees > 0 ? turn_right : turn_left
+    degrees > 0 ? East.new : West.new
   end
   def forward(location, plateau)
     plateau.increment(:y, location)
lib/south.rb
@@ -1,12 +1,6 @@
 class South
-  def turn_right
-    West.new
-  end
-  def turn_left
-    East.new
-  end
   def rotate(degrees)
-    degrees > 0 ? turn_right : turn_left
+    degrees > 0 ? West.new : East.new
   end
   def forward(location, plateau)
     plateau.decrement(:y, location)
lib/west.rb
@@ -1,12 +1,6 @@
 class West
-  def turn_right
-    North.new
-  end
-  def turn_left
-    South.new
-  end
   def rotate(degrees)
-    degrees > 0 ? turn_right : turn_left
+    degrees > 0 ? North.new : South.new
   end
   def forward(location, plateau)
     plateau.decrement(:x, location)
spec/unit/east_spec.rb
@@ -15,12 +15,12 @@ describe East do
   end
   context "when turning right" do
     it "should face South" do
-      sut.turn_right.should be_an_instance_of(South)
+      sut.rotate(90).should be_an_instance_of(South)
     end
   end
   context "when turning left" do
     it "should face North" do
-      sut.turn_left.should be_an_instance_of(North)
+      sut.rotate(-90).should be_an_instance_of(North)
     end
   end
   context "when displayed" do
spec/unit/north_spec.rb
@@ -14,12 +14,12 @@ describe North do
   end
   context "when turning right" do
     it "should face east" do
-      sut.turn_right.should be_an_instance_of(East)
+      sut.rotate(90).should be_an_instance_of(East)
     end
   end
   context "when turning left" do
     it "should face west" do
-      sut.turn_left.should be_an_instance_of(West)
+      sut.rotate(-90).should be_an_instance_of(West)
     end
   end
   context "when displayed" do
spec/unit/south_spec.rb
@@ -14,12 +14,12 @@ describe South do
   end
   context "when turning left" do
     it "should face east" do
-      sut.turn_left.should be_an_instance_of(East)
+      sut.rotate(-90).should be_an_instance_of(East)
     end
   end
   context "when turning right" do
     it "should face west" do
-      sut.turn_right.should be_an_instance_of(West)
+      sut.rotate(90).should be_an_instance_of(West)
     end
   end
   context "when displayed" do
spec/unit/west_spec.rb
@@ -15,12 +15,12 @@ describe West do
   end
   context "when turning right" do
     it "should face North" do
-      sut.turn_right.should be_an_instance_of(North)
+      sut.rotate(90).should be_an_instance_of(North)
     end
   end
   context "when turning left" do
     it "should face South" do
-      sut.turn_left.should be_an_instance_of(South)
+      sut.rotate(-90).should be_an_instance_of(South)
     end
   end
   context "when displayed" do