If you pass a numeric parameter to first or last, you'll get that number of items from the start or the end of the array : first « Array « Ruby






If you pass a numeric parameter to first or last, you'll get that number of items from the start or the end of the array


x = [1, 2, 3]
puts x.first(2).join("-")

 

Related examples in the same category

1.Access the First and Last Elements of the Array