I have a method:
def deltas_to_board_locations(deltas, x, y)
board_coords = []
deltas.each_slice(2) do |slice|
board_coords << x + slice[0]
board_coords << y + slice[1]
end
board_coords
end
where deltas is an array, and x,y are fixnums.
Is there a way to eliminate the first and last line to make the method more elegant?
Like:
def deltas_to_board_locations(deltas, x, y)
deltas.each_slice(2) do |slice|
board_coords << x + slice[0]
board_coords << y + slice[1]
end
end
The above works for Ruby 1.9 , but I agree with Renaud. The obvious solution is to be preferred, and in this case is faster than mine, too.
Edit: Incorporated @tokland’s comments.