Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5
If you don't need index of an element in a data structure and you only need the contained elements, it is easier using iterators. myarray=[1,2,3] for element in myarray puts element end If you need the element index for some reason, you could do it like this: for index in 0..myarray.size-1 # do something with index puts myarray[index] end Or myarray.each_index do |index| # do something with index puts myarray[index] end
19th Jan 2019, 12:32 PM
Javier Felipe Toribio
Javier Felipe Toribio - avatar