Collect method - another .each?


#1



https://www.codecademy.com/en/courses/ruby-beginner-en-L3ZCI/0/2?curriculum_id=5059f8619189a5000201fbcb


It looks to me like the ".collect" method and ".each" method are the same. But i might be wrong, what do you guys say?


fibs = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]

doubled_fibs = fibs.collect { |num| num * 2 }


#2

The different between the two methods is that...

Each Method is just used for looping, it returns self. So it's like the for loop
Whereas the Collect method appends each item to an array and returns that array instead.

Regards,
Barry Allen