"Humane" programmer interfaces

colinwb colinwb at yahoo.co.uk
Thu Dec 29 12:50:57 EST 2005


Apologies if I'm misunderstanding some points in kpd's post, but:

http://www.rubycentral.com/ref/ref_c_array.html

[ ]
arr[anInteger] -> anObject or nil
arr[start, length] -> aSubArray or nil
arr[aRange] -> aSubArray or nil

Element Reference

Returns the element at index anInteger, or returns a subarray starting
at index start and continuing for length elements, or

returns a subarray specified by aRange. Negative indices count backward
from the end of the array (-1 is the last element).

Returns nil if any indices are out of range.

[ ]=
arr[anInteger] = anObject -> anObject
arr[start, length] = aSubArray -> aSubArray
arr[aRange] = aSubArray -> aSubArray


http://tryruby.hobix.com

Interactive ruby ready.
>> ck = Array [ 'C', 'K', 'S', 'vvg' ]
=> ["C", "K", "S", "vvg"]

>> puts ck.first, ck[0], '*', ck.last, ck[-1]
           C       C      *     vvg      vvg
=> nil

>> puts ck[0..2], '*', ck[-4..-2]
        C  K  S    *    C  K  S
=> nil

>> puts ck.size, ck.length
               4          4
=> nil

(The print elements in these example were actually
printed on separate lines. I've put them on the
same line for clarity and to save email space.)




More information about the Python-list mailing list