## Reference: https://womanonrails.com/each-with-object
# Bad
array = []
(1..10).each do |item|
array << item ** 2
end
array
# Good
(1..10).each_with_object([]) do |item, array|
array << item ** 2
end
Last active
October 8, 2021 20:02
-
-
Save wowremywang/cae159456cece85fd3876791c1cea877 to your computer and use it in GitHub Desktop.
Helpful methods
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment