Arrays and Blocks : each « Array « Ruby






Arrays and Blocks


# each lets you iterate over every element in an array and do something to it. 

month_a = %w[ nil jan feb mar apr may jun jul aug sep oct nov dec ] 

month_a.each { |e| print e.capitalize + " " }

 








Related examples in the same category

1.Assign block value to a variable in array each method
2.Iterating Over an Array with each
3.each with block which has if statement
4.LocalJumpError: no block given