random-accessible
RandomAccessible mixin provides all methods of Array to your classes (regard as high-functioning edition of Enumerable). As Enumerable mixin requests "each" method, RandomAccessible requests methods below.
- size (same as Array#size)
- read_access (similar to Array#[])
- replace_access (similar to Array#[]=)
- shrink (similar to Array#pop)
size method returns the number of objects which the object contains. Note that this method must behave same as Array's.
read_access(pos) is similar to Array#[]. But the module guarantees that the argument is an Integer larger than or equal 0 and less than its size.
replace_access(pos, val) is similar to Array#[]=. The module guarantees that the argument pos is an Integer and 0 <= pos < size.
shrink is similar to Array#pop. But the method can return anything.
Installation
gem install random-accessible
Limitation
Behavior of RandomAccessible#eql? is different from Array's. The method always returns false if the argument does not include RandomReadable (RandomAccessible includes RandomReadable). Also note that Array#eql? returns false if the arguent is RandomAccessible.
License
This library is distributed under the dual license of the Ruby license (in the narrow sense) and the 2-clause BSD license. Please see http://www.ruby-lang.org and BSDL. Copyright (c) 2011, Natsuki Kawai.