You can use each_with_index and then use an index to identify the first and last elements. For example:
@data.each_with_index do |item, index| if index == 0
Alternatively, if you prefer, you can separate the "middle" array as follows:
In both of these methods, you must be careful with the desired behavior if there is only one or two elements in the list.
thomasfedb
source share