diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-08-23 01:07:30 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-23 01:07:30 -0300 |
commit | 58e0b1d6fc5b6762fbe667c24d808d76b57c7914 (patch) | |
tree | a0b82516318ea5101300f44a9bb7a983fd4dc6c0 | |
parent | cea338d82e2eeebd355401883d785301c880d647 (diff) | |
parent | f5ce0f39c6bd3831bf8f7f9ec6a4664330a7bc28 (diff) | |
download | rails-58e0b1d6fc5b6762fbe667c24d808d76b57c7914.tar.gz rails-58e0b1d6fc5b6762fbe667c24d808d76b57c7914.tar.bz2 rails-58e0b1d6fc5b6762fbe667c24d808d76b57c7914.zip |
Merge pull request #26228 from kamipo/remove_unnecessary_any_and_many
Remove unnecessary `any?` and `many?` methods for collection proxy
-rw-r--r-- | activerecord/lib/active_record/associations/collection_association.rb | 22 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/collection_proxy.rb | 18 |
2 files changed, 12 insertions, 28 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index a02ec032a7..0f51b35164 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -286,28 +286,6 @@ module ActiveRecord end end - # Returns true if the collections is not empty. - # If block given, loads all records and checks for one or more matches. - # Otherwise, equivalent to +!collection.empty?+. - def any? - if block_given? - load_target.any? { |*block_args| yield(*block_args) } - else - !empty? - end - end - - # Returns true if the collection has more than 1 record. - # If block given, loads all records and checks for two or more matches. - # Otherwise, equivalent to +collection.size > 1+. - def many? - if block_given? - load_target.many? { |*block_args| yield(*block_args) } - else - size > 1 - end - end - def distinct seen = {} load_target.find_all do |record| diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index ffdd1c04a3..48436155ce 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -851,6 +851,12 @@ module ActiveRecord @association.empty? end + ## + # :method: any? + # + # :call-seq: + # any?() + # # Returns +true+ if the collection is not empty. # # class Person < ActiveRecord::Base @@ -880,10 +886,13 @@ module ActiveRecord # pet.group == 'dogs' # end # # => true - def any?(&block) - @association.any?(&block) - end + ## + # :method: many? + # + # :call-seq: + # many?() + # # Returns true if the collection has more than one record. # Equivalent to <tt>collection.size > 1</tt>. # @@ -918,9 +927,6 @@ module ActiveRecord # pet.group == 'cats' # end # # => true - def many?(&block) - @association.many?(&block) - end # Returns +true+ if the given +record+ is present in the collection. # |