what’s different between each and collect method in Ruby [duplicate]
Array#each takes an array and applies the given block over all items. It doesn’t affect the array or creates a new object. It is just a way of looping over items. Also it returns self. 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 is same as Array#map and it … Read more