From 6720c0aeeba1921010ae96325b1d4caba33794c5 Mon Sep 17 00:00:00 2001 From: zzak Date: Thu, 7 Nov 2013 17:15:49 +0000 Subject: [PATCH] * array.c: [DOC] Add note about negative indices in Array overview By @ckaenzig [Fixes GH-427] https://github.com/ruby/ruby/pull/427 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ array.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 78c5bd51ea..c9e2461601 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Nov 8 02:14:37 2013 Zachary Scott + + * 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 * lib/csv.rb: [DOC] Fix typo in CSV.parse_line by @funky-bibimbap diff --git a/array.c b/array.c index 1a71f1b459..5d01fdb551 100644 --- a/array.c +++ b/array.c @@ -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 *