csherin/mazes — Issue #6: Sigma#distance_y_axis is pretty long
Author: PragTob
Created: 2012-01-20 19:13:05+00:00
State: open

istance_y_axis seems pretty long to me, however I don't really have suggestions on how to make it shorter (just putting the ifs into methods, dunno if this is worth it though). Can you think of something?

the method (for reference):

def distance_y_axis(direction, coordinate=nil, units=1)
case direction
when :north
noexit_north?(coordinate) ? 0 : -units
when :south
noexit_south?(coordinate) ? 0 : units
when :north_west
if noexit_north_west?(coordinate)
0
else
shifted_up?(coordinate) ? -units : 0
end
when :north_east
if noexit_north_east?(coordinate)
0
else
shifted_up?(coordinate) ? -units : 0
end
when :south_west
if noexit_south_west?(coordinate)
0
else
shifted_down?(coordinate) ? units : 0
end
when :south_east
if noexit_south_east?(coordinate)
0
else
shifted_down?(coordinate) ? units : 0
end
end
end