Get the first and last elements of an array is with the first and last methods : last « Array « Ruby






Get the first and last elements of an array is with the first and last methods



q1 = %w[ January February March ]
q1.first # => January
q1.last # => March

 

Related examples in the same category

1.Both first and last take integer arguments, indicating the number of elements to return