The first() is an inbuilt method in Ruby returns an array of first X elements. If X is not mentioned, it returns the first element only.
Parameters: The function accepts X which is the number of elements from the beginning.
Return Value: It returns an array of first X elements.
0 1 2
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.