aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorBrian Christian <brchristian@gmail.com>2016-02-09 16:02:08 -0800
committerBrian Christian <brchristian@gmail.com>2016-02-09 16:02:08 -0800
commitc74045cf0771ab51dfeca94b30c447cab6193e60 (patch)
tree277b16c5e586866a7284b63ac753035a7f81dd3e /activesupport/lib/active_support
parentb5eb2423b6e431ba53e3836d58449e7e810096b4 (diff)
downloadrails-c74045cf0771ab51dfeca94b30c447cab6193e60.tar.gz
rails-c74045cf0771ab51dfeca94b30c447cab6193e60.tar.bz2
rails-c74045cf0771ab51dfeca94b30c447cab6193e60.zip
allow Array.penultimate and Array.antepenultiate access methods
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/core_ext/array/access.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/access.rb b/activesupport/lib/active_support/core_ext/array/access.rb
index 3177d8498e..e413acddc5 100644
--- a/activesupport/lib/active_support/core_ext/array/access.rb
+++ b/activesupport/lib/active_support/core_ext/array/access.rb
@@ -73,4 +73,18 @@ class Array
def forty_two
self[41]
end
+
+ # Equal to <tt>self[-3]</tt>.
+ #
+ # %w( a b c d e ).antepenultimate # => "c"
+ def antepenultimate
+ self[-3]
+ end
+
+ # Equal to <tt>self[-2]</tt>.
+ #
+ # %w( a b c d e ).penultimate # => "d"
+ def penultimate
+ self[-2]
+ end
end