1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Consolidate duplicated to_ary/to_a definitions in Relation and CollectionProxy

This commit is contained in:
Ryuta Kamizono 2017-11-10 23:33:39 +09:00
parent df49896a1e
commit b1e068bd30
3 changed files with 9 additions and 6 deletions

View file

@ -988,6 +988,12 @@ module ActiveRecord
load_target == other
end
##
# :method: to_ary
#
# :call-seq:
# to_ary()
#
# Returns a new array of objects from the collection. If the collection
# hasn't been loaded, it fetches the records from the database.
#
@ -1021,10 +1027,6 @@ module ActiveRecord
# # #<Pet id: 5, name: "Brain", person_id: 1>,
# # #<Pet id: 6, name: "Boss", person_id: 1>
# # ]
def to_ary
load_target.dup
end
alias_method :to_a, :to_ary
def records # :nodoc:
load_target

View file

@ -243,9 +243,10 @@ module ActiveRecord
end
# Converts relation objects to Array.
def to_a
def to_ary
records.dup
end
alias to_a to_ary
def records # :nodoc:
load

View file

@ -38,7 +38,7 @@ module ActiveRecord
# may vary depending on the klass of a relation, so we create a subclass of Relation
# for each different klass, and the delegations are compiled into that subclass only.
delegate :to_xml, :encode_with, :length, :each, :uniq, :to_ary, :join,
delegate :to_xml, :encode_with, :length, :each, :uniq, :join,
:[], :&, :|, :+, :-, :sample, :reverse, :rotate, :compact, :in_groups, :in_groups_of,
:to_sentence, :to_formatted_s, :as_json,
:shuffle, :split, :slice, :index, :rindex, to: :records