aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-02-24 10:25:13 -0500
committerGitHub <noreply@github.com>2017-02-24 10:25:13 -0500
commitd31178fb80bba46675340b210a48be1318fece2a (patch)
tree73b051e99c45b427e67e3e7eff59020d3419b877 /activerecord
parentbf388ecfc22d91f9716aca82cc4da5b583d87f17 (diff)
parentd9fd1479181b8be6c080e9b3186fb48283ba68df (diff)
downloadrails-d31178fb80bba46675340b210a48be1318fece2a.tar.gz
rails-d31178fb80bba46675340b210a48be1318fece2a.tar.bz2
rails-d31178fb80bba46675340b210a48be1318fece2a.zip
Merge pull request #28145 from treiff/update-docs-ActiveRecord__Result
Improve docs for ActiveRecord::Result. [ci skip]
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/result.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/result.rb b/activerecord/lib/active_record/result.rb
index 9ed70a9c2b..26b1d48e9e 100644
--- a/activerecord/lib/active_record/result.rb
+++ b/activerecord/lib/active_record/result.rb
@@ -41,10 +41,15 @@ module ActiveRecord
@column_types = column_types
end
+ # Returns the number of elements in the rows array.
def length
@rows.length
end
+ # Calls the given block once for each element in row collection, passing
+ # row as parameter.
+ #
+ # Returns an +Enumerator+ if no block is given.
def each
if block_given?
hash_rows.each { |row| yield row }
@@ -53,6 +58,7 @@ module ActiveRecord
end
end
+ # Returns an array of hashes representing each row record.
def to_hash
hash_rows
end
@@ -60,11 +66,12 @@ module ActiveRecord
alias :map! :map
alias :collect! :map
- # Returns true if there are no records.
+ # Returns true if there are no records, otherwise false.
def empty?
rows.empty?
end
+ # Returns an array of hashes representing each row record.
def to_ary
hash_rows
end
@@ -73,11 +80,15 @@ module ActiveRecord
hash_rows[idx]
end
+ # Returns the first record from the rows collection.
+ # If the rows collection is empty, returns +nil+.
def first
return nil if @rows.empty?
Hash[@columns.zip(@rows.first)]
end
+ # Returns the last record from the rows collection.
+ # If the rows collection is empty, returns +nil+.
def last
return nil if @rows.empty?
Hash[@columns.zip(@rows.last)]