From c74045cf0771ab51dfeca94b30c447cab6193e60 Mon Sep 17 00:00:00 2001 From: Brian Christian Date: Tue, 9 Feb 2016 16:02:08 -0800 Subject: allow Array.penultimate and Array.antepenultiate access methods --- activesupport/lib/active_support/core_ext/array/access.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'activesupport/lib/active_support') 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 self[-3]. + # + # %w( a b c d e ).antepenultimate # => "c" + def antepenultimate + self[-3] + end + + # Equal to self[-2]. + # + # %w( a b c d e ).penultimate # => "d" + def penultimate + self[-2] + end end -- cgit v1.2.3