Easy, just include the Enumerable module and define an instance method each , which will most often use some other method of the each class. Here's a really simplified example:
class ATeam include Enumerable def initialize(*members) @members = members end def each(&block) @members.each do |member| block.call(member) end # or # @members.each(&block) end end ateam = ATeam.new("Face", "BA Barracus", "Murdoch", "Hannibal") #use any Enumerable method from here on p ateam.map(&:downcase)
For more information, I recommend the following article: Ruby Enumerable Magic: The Basics .
In the context of your question, if what you open through the accessor is already a collection, you probably don't need to worry about enabling Enumerable .
Michael Kohl Aug 28 2018-11-11T00: 00Z
source share