I've been trying to design my read only Array data structure and I really like the idea of providing traversing options with Enumerable class, but I cannot find requirements of it. In some examples that I've looked, the C implementation looks for #each
method, but it seems to me that it can't be enough.
Asked
Active
Viewed 427 times
4

Translunar
- 3,739
- 33
- 55

farnoy
- 7,356
- 2
- 20
- 30
-
1FYI, `Enumerable` is a module, not a class. – Frost Jan 20 '12 at 14:46
1 Answers
8
From Pickaxe p. 474 and also from the core documentation:
The class [mixing in Enumerable] must provide a method
each
, which yields successive members of the collection. IfEnumerable#max
,min
,sort
, orsort_by
is used, the objects in the collection must also implement a meaningful<=>
operator, because these methods rely on an ordering between members of a collection.

Wayne Conrad
- 103,207
- 26
- 155
- 191
-
2The same said in ruby documentation: http://ruby-doc.org/core-1.9.3/Enumerable.html – Aliaksei Kliuchnikau Jan 20 '12 at 14:45
-