diff options
| author | mo k <mo@mokhan.ca> | 2012-02-11 15:36:47 -0700 |
|---|---|---|
| committer | mo k <mo@mokhan.ca> | 2012-02-11 15:36:47 -0700 |
| commit | d573d01a53f20cbbd2f390b7678f0ee56177240f (patch) | |
| tree | ce6f6dbeea544f7a88fd06a699c10c4415efebd5 /lib | |
| parent | d7a2e10529ebed062252b304dcb9c25e788b58ae (diff) | |
refactor conditional using a hash.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/rover.rb | 11 |
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 |
