You are viewing a single comment's thread. Return to all comments →
The problem/lesson is clear to me it talks about how iterate over a collection using Enumerable module.
And states "As long as the custom object defines an each method and includes Enumerable module, it can get access to all of its magic."
And asks for" You need to iterate over the items and return an Array containing the values."
So that we have to use "each" method.
My simple solution as follows:
def iterate_colors(colors) arr = Array.new colors.each {|i| arr<<i} return arr end
Seems like cookies are disabled on this browser, please enable them to open this website
Ruby - Enumerable - Introduction
You are viewing a single comment's thread. Return to all comments →
The problem/lesson is clear to me it talks about how iterate over a collection using Enumerable module.
And states "As long as the custom object defines an each method and includes Enumerable module, it can get access to all of its magic."
And asks for" You need to iterate over the items and return an Array containing the values."
So that we have to use "each" method.
My simple solution as follows: