Skip to content

Latest commit

 

History

History
20 lines (14 loc) · 238 Bytes

each_vs_map.md

File metadata and controls

20 lines (14 loc) · 238 Bytes

Each vs map

Let the following each:

user_ids = []
users.each { |user| user_ids << user.id }

It can be simplified to:

user_ids = users.map { |user| user.id }

or even:

user_ids = users.map(&:id)