Ruby - Enumerable - Introduction

  • + 0 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