Say I have a custom class, what should I override to get array-like behaviour? I think that supplying an each method won’t be enough, as that won’t give me acces to the [] methods?
Should I inherit the Array class? What should I overwrite in there?
For enumerable like behavior (which sounds like what you want), you should
include Enumerableto get theEnumerablemodule functionality, which means you need to provide a methodeach. This will give you lots of the relevant methods you want (Enumerable details).If you want just
[]like functionality, you only need the following methods, and nothing more: