each method goes through each element of the array and passes it as a parameter to the code block you supply. : Array Each « Array « Ruby






each method goes through each element of the array and passes it as a parameter to the code block you supply.


[1, "test", 2, 3, 4].each { |element| puts element.to_s + "X" }

 

Related examples in the same category

1.If you have a collection, such as an array or a range, you can also use the Ruby each iterator to create a loop.
2.Identify the Array and Hash of Customers