DEV Community

Discussion on: handy Ruby methods #2 - Object#tap

Collapse
 
andy4thehuynh profile image
Andy Huynh

You got it!

Yeah, it's overkill but you can do something like this for the first example w/ tap:

something = (1..10)

[].tap do |arr|
  something.each { |num| arr << num * 2 }
end

This will return the array which is great in some cases.