- Gain more practice with the
yield
keyword and blocks - Gain a deeper understanding of how a common interator, `.collect
Fork and clone this repository. Run the test suite to get a better understanding of what is being asked of you. You'll write your code in "my_collect.rb".
You are writing a method that behaves just like the real .collect
method. It should take in an argument of a collection, iterate over that collection, and execute the code in the block you call it with for each element in the collection. It should return the modified collection.
For example:
array = [1, 2, 3, 4]
my_collect(array) do |i|
i * 2
end
Should return:
[2, 4, 6, 8]
Don't use Ruby's .each
method to solve this lab. Rely on the yield
keyword to yield each element in the collection to the block that my_collect
is called with.