summaryrefslogtreecommitdiff
path: root/lib/csv
diff options
context:
space:
mode:
authorBurdette Lamar <[email protected]>2020-08-11 19:48:00 -0500
committerSutou Kouhei <[email protected]>2020-11-24 09:33:55 +0900
commit72997f48672648d65ffad44607b9471814156253 ()
treea2575cbacc0021f1b8c11b67f017b4bd9ddc1d34 /lib/csv
parent3283ef1a7e7b1e2f7063c3078be0a868a37aa710 (diff)
[ruby/csv] Enhanced RDoc for values_at, <<, and push (#164)
https://.com/ruby/csv/commit/bb3eb242f2
Notes: Merged: https://.com/ruby/ruby/pull/3804
-rw-r--r--lib/csv/table.rb89
1 files changed, 74 insertions, 15 deletions
@@ -287,15 +287,58 @@ class CSV
end
end
#
- # The mixed mode default is to treat a list of indices as row access,
- # returning the rows indicated. Anything else is considered columnar
- # access. For columnar access, the return set has an Array for each row
- # with the values indicated by the headers in each Array. You can force
- # column or row mode using by_col!() or by_row!().
#
- # You cannot mix column and row access.
#
def values_at(*indices_or_headers)
if @mode == :row or # by indices
( @mode == :col_or_row and indices_or_headers.all? do |index|
@@ -310,13 +353,20 @@ class CSV
end
end
#
- # Adds a new row to the bottom end of this table. You can provide an Array,
- # which will be converted to a CSV::Row (inheriting the table's headers()),
- # or a CSV::Row.
- #
- # This method returns the table for chaining.
#
def <<(row_or_array)
if row_or_array.is_a? Array # append Array
@table << Row.new(headers, row_or_array)
@@ -328,12 +378,21 @@ class CSV
end
#
- # A shortcut for appending multiple rows. Equivalent to:
- #
- # rows.each { |row| self << row }
#
- # This method returns the table for chaining.
#
def push(*rows)
rows.each { |row| self << row }