Array#each takes an array and applies the given block to all elements. It does not affect the array or creates a new object. This is just a way to iterate over elements. He also returns himself.
arr=[1,2,3,4] arr.each {|x| puts x*2}
Prints 2,4,6,8 and returns [1,2,3,4] no matter what
Array#collect same as Array#map and applies this block of code to all elements and returns a new array. just put 'Projects each element of the sequence into a new shape
arr.collect {|x| x*2}
Returns [2,4,6,8]
And in your code
a = ["L","Z","J"].collect{|x| puts x.succ}
a is an array, but itโs actually an array from Nil [nil, nil, nil] , because puts x.succ returns nil (even if it prints M AA K).
AND
b = ["L","Z","J"].each{|x| puts x.succ}
also an array. But its value is ["L", "Z", "J"], because it returns self.
RameshVel Mar 18 2018-11-11T00: 00Z
source share