each is different from map and collect , but map and collect are the same
each performs the enclosed block for each element in the receiver
[1,2,3,4].each {|n| puts n*2}
# Outputs:
# 2
# 4
# 6
# 8
map and collect produce a new Array containing the results of the block applied to each ekenebt if the receiver[1,2,3,4].map {|n| n*2}
# => [2,4,6,8]
沒有留言:
張貼留言