diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | array.c | 4 |
2 files changed, 8 insertions, 1 deletions
@@ -1,3 +1,8 @@ +Fri Nov 8 02:14:37 2013 Zachary Scott <e@zzak.io> + + * array.c: [DOC] Add note about negative indices in Array overview + By @ckaenzig [Fixes GH-427] https://github.com/ruby/ruby/pull/427 + Fri Nov 8 02:09:12 2013 Zachary Scott <e@zzak.io> * lib/csv.rb: [DOC] Fix typo in CSV.parse_line by @funky-bibimbap @@ -5404,7 +5404,8 @@ rb_ary_drop_while(VALUE ary) * * Elements in an array can be retrieved using the Array#[] method. It can * take a single integer argument (a numeric index), a pair of arguments - * (start and length) or a range. + * (start and length) or a range. Negative indices start counting from the end, + * with -1 being the last element. * * arr = [1, 2, 3, 4, 5, 6] * arr[2] #=> 3 @@ -5412,6 +5413,7 @@ rb_ary_drop_while(VALUE ary) * arr[-3] #=> 4 * arr[2, 3] #=> [3, 4, 5] * arr[1..4] #=> [2, 3, 4, 5] + * arr[1..-3] #=> [2, 3, 4] * * Another way to access a particular array element is by using the #at method * |