diff options
author | Trevor Reiff <trevorreiff@gmail.com> | 2017-02-23 22:00:59 -0500 |
---|---|---|
committer | Trevor Reiff <trevorreiff@gmail.com> | 2017-02-24 08:27:08 -0500 |
commit | d9fd1479181b8be6c080e9b3186fb48283ba68df (patch) | |
tree | 856a6b510e5eeaa9b177f8ddeb9abd09c7570731 | |
parent | 4ed704740b7ccc8ac9cfb7b5ec62d55ac178ec97 (diff) | |
download | rails-d9fd1479181b8be6c080e9b3186fb48283ba68df.tar.gz rails-d9fd1479181b8be6c080e9b3186fb48283ba68df.tar.bz2 rails-d9fd1479181b8be6c080e9b3186fb48283ba68df.zip |
Improve docs for ActiveRecord::Result. [ci skip]
Remove styling from `true` and `false`.
-rw-r--r-- | activerecord/lib/active_record/result.rb | 13 |
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)] |