summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormo k <mo@mokhan.ca>2012-02-11 15:36:47 -0700
committermo k <mo@mokhan.ca>2012-02-11 15:36:47 -0700
commitd573d01a53f20cbbd2f390b7678f0ee56177240f (patch)
treece6f6dbeea544f7a88fd06a699c10c4415efebd5 /lib
parentd7a2e10529ebed062252b304dcb9c25e788b58ae (diff)
refactor conditional using a hash.
Diffstat (limited to 'lib')
-rw-r--r--lib/rover.rb11
1 files changed, 2 insertions, 9 deletions
diff --git a/lib/rover.rb b/lib/rover.rb
index 2f48cb5..f5bfa7d 100644
--- a/lib/rover.rb
+++ b/lib/rover.rb
@@ -59,15 +59,8 @@ class South
end
class Direction
+ @@directions = {:north => North.new, :east => East.new, :west => West.new, :south => South.new}
def self.find(heading)
- if(heading == :north)
- return North.new
- elsif heading == :east
- return East.new
- elsif heading == :south
- return South.new
- elsif heading == :west
- return West.new
- end
+ @@directions[heading]
end
end