Ruby Enumerables - what are they?

Can someone explain in the simplest, simplest terms what Ruby is Enumerable

? I am very new to coding and am just getting started with arrays and hashes. I've read the word "enumerated" everywhere, but I don't understand what it is.

+1


source to share


2 answers


Can someone explain, in the simplest, simplest terms, what Ruby is going to list?

It's a module that defines a bunch of methods, and when another class includes that module, those methods are available in that class. So if someone is using a type method each_with_index

on an array and you say to yourself, "I'm wondering how this method works. I'll check the Array docs." You won't find this method in the Array docs. When you're looking for a method definition and can't find it in the Array docs, you need to look at the Array docs to see what modules are included in the Array class; then you will see that Array includes Enumerable. This way you can click the Enumerable link and there you will find the definition for each_with_index. Try it.



I think what you really mean is: what is an Enumerator?

And an enumerator is a thing that can perform (like iterating over) the elements of a collection (Array, Hash, etc.). However, if you are just getting started coding, you only need to worry about how to find method definitions in the docs, and hopefully the above will pick that up. Lists are on the horizon for your future.

+1


source


From the docs :



The enumerated mixin provides collection classes with multiple traversal and search methods, and sorting capability. the class must provide every method that yields consecutive members of the collection.

0


source







All Articles