3件ヒット
[1-3件を表示]
(0.012秒)
検索結果
先頭3件
-
CSV
:: Row # fields(*headers _ and _ or _ indices) -> Array (54616.0) -
与えられた引数に対応する値の配列を返します。
...与えられた引数に対応する値の配列を返します。
要素の探索に CSV::Row.field を使用しています。
@param headers_and_or_indices ヘッダの名前かインデックスか Range
のインスタンスか第 1 要素がヘッダの名前......るこ
とができます。
@return 引数を与えなかった場合は全ての要素を返します。
require 'csv'
csv = CSV.new("a,b,c\n1,2,3", headers: true)
table = csv.read
row = table.first
row.values_at("a", 1, 2..3) # => ["1", "2", "3", nil]... -
CSV
:: Row # values _ at(*headers _ and _ or _ indices) -> Array (9316.0) -
与えられた引数に対応する値の配列を返します。
...与えられた引数に対応する値の配列を返します。
要素の探索に CSV::Row.field を使用しています。
@param headers_and_or_indices ヘッダの名前かインデックスか Range
のインスタンスか第 1 要素がヘッダの名前......るこ
とができます。
@return 引数を与えなかった場合は全ての要素を返します。
require 'csv'
csv = CSV.new("a,b,c\n1,2,3", headers: true)
table = csv.read
row = table.first
row.values_at("a", 1, 2..3) # => ["1", "2", "3", nil]... -
CSV (61.0)
-
このクラスは CSV ファイルやデータに対する完全なインターフェイスを提供します。
...は CSV ファイルやデータに対する完全なインターフェイスを提供します。
=== 読み込み
//emlist[][ruby]{
require "csv"
csv_text = <<~CSV_TEXT
Ruby,1995
Rust,2010
CSV_TEXT
IO.write "sample.csv", csv_text
# ファイルから一行ずつ
CSV.foreach("sample.csv")......010"]
# ファイルから一度に
p CSV.read("sample.csv")
# => [["Ruby", "1995"], ["Rust", "2010"]]
# 文字列から一行ずつ
CSV.parse(csv_text) do |row|
p row
end
# => ["Ruby", "1995"]
# ["Rust", "2010"]
# 文字列から一度に
p CSV.parse(csv_text)
# => [["Ruby", "1995"], ["Rust......][ruby]{
require 'csv'
# ファイルへ書き込み
CSV.open("path/to/file.csv", "wb") do |csv|
csv << ["row", "of", "CSV", "data"]
csv << ["another", "row"]
# ...
end
# 文字列へ書き込み
csv_string = CSV.generate do |csv|
csv << ["row", "of", "CSV", "data"]
csv << ["another", "r...