What is the difference between map, each, and collect? [duplicate]
问题 This question already has an answer here: what's different between each and collect method in Ruby [duplicate] 7 answers In Ruby, is there any difference between the functionalities of each , map , and collect ? 回答1: each is different from map and collect , but map and collect are the same (technically map is an alias for collect , but in my experience map is used a lot more frequently). each performs the enclosed block for each element in the ( Enumerable ) receiver: [1,2,3,4].each {|n| puts