提交 d31178fb 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #28145 from treiff/update-docs-ActiveRecord__Result

Improve docs for ActiveRecord::Result. [ci skip]
......@@ -41,10 +41,15 @@ def initialize(columns, rows, column_types = {})
@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 @@ def each
end
end
# Returns an array of hashes representing each row record.
def to_hash
hash_rows
end
......@@ -60,11 +66,12 @@ def to_hash
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 @@ def [](idx)
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)]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册