Both first and last take integer arguments, indicating the number of elements to return : last « Array « Ruby






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


q1 = %w[ January February March ]
q1.first 2 # => ["January", "February"]
q1.last 0 # => [] not particularly useful

 

Related examples in the same category

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