each | map / collect | |
|---|---|---|
| Return | object gốc (self) | array mới chứa kết quả |
| Mục đích | side-effect (in, ghi file...) | biến đổi, tạo dữ liệu mới |
Quy tắc: Nếu không dùng giá trị trả về → each. Nếu cần array mới → map. map! biến đổi in-place (thay đổi array gốc).
each | map / collect | |
|---|---|---|
| Returns | original object (self) | new array of results |
| Purpose | side-effects (printing, writing...) | transforming, producing new data |
Rule: if you discard the return value → each. If you need the new array → map. map! mutates in-place.