diff options
author | Brian Christian <brchristian@gmail.com> | 2016-02-10 10:10:38 -0800 |
---|---|---|
committer | Brian Christian <brchristian@gmail.com> | 2016-02-10 10:10:38 -0800 |
commit | e8aeda2ab39b5d416a72edfa74e0fb17721eb6f9 (patch) | |
tree | ea2b76a40f9d9ce3046a9fae3f177b9e4c0b1706 | |
parent | c74045cf0771ab51dfeca94b30c447cab6193e60 (diff) | |
download | rails-e8aeda2ab39b5d416a72edfa74e0fb17721eb6f9.tar.gz rails-e8aeda2ab39b5d416a72edfa74e0fb17721eb6f9.tar.bz2 rails-e8aeda2ab39b5d416a72edfa74e0fb17721eb6f9.zip |
rename to 'second_to_last' and 'third_to_last'
8 files changed, 32 insertions, 32 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 6927f1fca3..2dca6b612e 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -136,12 +136,12 @@ module ActiveRecord first_nth_or_last(:forty_two, *args) end - def antepenultimate(*args) - first_nth_or_last(:antepenultimate, *args) + def third_to_last(*args) + first_nth_or_last(:third_to_last, *args) end - def penultimate(*args) - first_nth_or_last(:penultimate, *args) + def second_to_last(*args) + first_nth_or_last(:second_to_last, *args) end def last(*args) diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index 5f3d4c6735..2a9627a474 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -198,13 +198,13 @@ module ActiveRecord end # Same as #first except returns only the third-to-last record. - def antepenultimate(*args) - @association.antepenultimate(*args) + def third_to_last(*args) + @association.third_to_last(*args) end # Same as #first except returns only the second-to-last record. - def penultimate(*args) - @association.penultimate(*args) + def second_to_last(*args) + @association.second_to_last(*args) end # Returns the last record, or the last +n+ records, from the collection. diff --git a/activerecord/lib/active_record/querying.rb b/activerecord/lib/active_record/querying.rb index 0a82832f56..5259797223 100644 --- a/activerecord/lib/active_record/querying.rb +++ b/activerecord/lib/active_record/querying.rb @@ -1,7 +1,7 @@ module ActiveRecord module Querying delegate :find, :take, :take!, :first, :first!, :last, :last!, :exists?, :any?, :many?, to: :all - delegate :second, :second!, :third, :third!, :fourth, :fourth!, :fifth, :fifth!, :forty_two, :forty_two!, :antepenultimate, :antepenultimate!, :penultimate, :penultimate!, to: :all + delegate :second, :second!, :third, :third!, :fourth, :fourth!, :fifth, :fifth!, :forty_two, :forty_two!, :third_to_last, :third_to_last!, :second_to_last, :second_to_last!, to: :all delegate :first_or_create, :first_or_create!, :first_or_initialize, to: :all delegate :find_or_create_by, :find_or_create_by!, :find_or_initialize_by, to: :all delegate :find_by, :find_by!, to: :all diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb index 90e05dc340..90a6a466fd 100644 --- a/activerecord/lib/active_record/relation/finder_methods.rb +++ b/activerecord/lib/active_record/relation/finder_methods.rb @@ -245,32 +245,32 @@ module ActiveRecord # Find the third-to-last record. # If no order is defined it will order by primary key. # - # Person.antepenultimate # returns the third-to-last object fetched by SELECT * FROM people - # Person.offset(3).antepenultimate # returns the third-to-last object from OFFSET 3 - # Person.where(["user_name = :u", { u: user_name }]).antepenultimate - def antepenultimate + # Person.third_to_last # returns the third-to-last object fetched by SELECT * FROM people + # Person.offset(3).third_to_last # returns the third-to-last object from OFFSET 3 + # Person.where(["user_name = :u", { u: user_name }]).third_to_last + def third_to_last find_nth -3 end - # Same as #antepenultimate but raises ActiveRecord::RecordNotFound if no record + # Same as #third_to_last but raises ActiveRecord::RecordNotFound if no record # is found. - def antepenultimate! + def third_to_last! find_nth! -3 end # Find the second-to-last record. # If no order is defined it will order by primary key. # - # Person.penultimate # returns the second-to-last object fetched by SELECT * FROM people - # Person.offset(3).penultimate # returns the second-to-last object from OFFSET 3 - # Person.where(["user_name = :u", { u: user_name }]).penultimate - def penultimate + # Person.second_to_last # returns the second-to-last object fetched by SELECT * FROM people + # Person.offset(3).second_to_last # returns the second-to-last object from OFFSET 3 + # Person.where(["user_name = :u", { u: user_name }]).second_to_last + def second_to_last find_nth -2 end - # Same as #penultimate but raises ActiveRecord::RecordNotFound if no record + # Same as #second_to_last but raises ActiveRecord::RecordNotFound if no record # is found. - def penultimate! + def second_to_last! find_nth! -2 end diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 4e9f7c330a..e975f4fbdd 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -408,13 +408,13 @@ class HasManyAssociationsTest < ActiveRecord::TestCase end assert_no_queries do - bulbs.antepenultimate() - bulbs.antepenultimate({}) + bulbs.third_to_last() + bulbs.third_to_last({}) end assert_no_queries do - bulbs.penultimate() - bulbs.penultimate({}) + bulbs.second_to_last() + bulbs.second_to_last({}) end assert_no_queries do diff --git a/activesupport/lib/active_support/core_ext/array/access.rb b/activesupport/lib/active_support/core_ext/array/access.rb index e413acddc5..37d833887a 100644 --- a/activesupport/lib/active_support/core_ext/array/access.rb +++ b/activesupport/lib/active_support/core_ext/array/access.rb @@ -76,15 +76,15 @@ class Array # Equal to <tt>self[-3]</tt>. # - # %w( a b c d e ).antepenultimate # => "c" - def antepenultimate + # %w( a b c d e ).third_to_last # => "c" + def third_to_last self[-3] end # Equal to <tt>self[-2]</tt>. # - # %w( a b c d e ).penultimate # => "d" - def penultimate + # %w( a b c d e ).second_to_last # => "d" + def second_to_last self[-2] end end diff --git a/activesupport/test/core_ext/array/access_test.rb b/activesupport/test/core_ext/array/access_test.rb index d7a3fb56c2..1d834667f0 100644 --- a/activesupport/test/core_ext/array/access_test.rb +++ b/activesupport/test/core_ext/array/access_test.rb @@ -26,8 +26,8 @@ class AccessTest < ActiveSupport::TestCase assert_equal array[3], array.fourth assert_equal array[4], array.fifth assert_equal array[41], array.forty_two - assert_equal array[-3], array.antepenultimate - assert_equal array[-2], array.penultimate + assert_equal array[-3], array.third_to_last + assert_equal array[-2], array.second_to_last end def test_without diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index 91cf48a680..10122629b2 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -2240,7 +2240,7 @@ Similarly, `from` returns the tail from the element at the passed index to the e [].from(0) # => [] ``` -The methods `second`, `third`, `fourth`, and `fifth` return the corresponding element (`first` is built-in), while `penultimate` and `antepenultimate` return the second-to-last and third-to-last elements, respectively. Thanks to social wisdom and positive constructiveness all around, `forty_two` is also available. +The methods `second`, `third`, `fourth`, and `fifth` return the corresponding element, as do `second_to_last` and `third_to_last` (`first` and `last` are built-in). Thanks to social wisdom and positive constructiveness all around, `forty_two` is also available. ```ruby %w(a b c d).third # => "c" |