4 ms·
My bad, sorry. The 'for..in' construct does not require you to expose the length of the structure. However, the other argument still holds true: In case of a u
by jasim 14y ago
My bad, sorry. The 'for..in' construct does not require you to expose the length of the structure.
However, the other argument still holds true: In case of a user-defined collection object, 'for..in' will not work since the underlying collection will be hidden.
- cdcarter 14y agoIn Ruby "for...in" is just syntactic sugar for #each. Try defining your own #each on a random object!
- roryokane 14y agoUnder the hood, 'for..in' just calls #each. Therefore, it is easy to make 'for..in' work with a custom collection: just define #each. And that is what you would do anyway if you were defining an Enumerable custom collection.