Assign block value to a variable in array each method : each « Array « Ruby






Assign block value to a variable in array each method


data = ['1', '2', '3']
s = ''
data.each { |x| s << x << ' and a '}

 








Related examples in the same category

1.Arrays and Blocks
2.Iterating Over an Array with each
3.each with block which has if statement
4.LocalJumpError: no block given