@example.each do |e| #do something here end
Here I want to do something different with the first and last element in each, how should I achieve this?
One of the nicer approaches is:
@example.tap do |head, *body, tail| head.do_head_specific_task! tail.do_tail_specific_task! body.each { |segment| segment.do_body_segment_specific_task! } end