るりまサーチ

最速Rubyリファレンスマニュアル検索!
33件ヒット [1-33件を表示] (0.040秒)
トップページ > クエリ:IO[x] > クエリ:generate_line[x]

別のキーワード

  1. openssl generate
  2. json generate
  3. csv generate_line
  4. dh generate
  5. csv generate

ライブラリ

クラス

キーワード

検索結果

CSV.generate_line(row, options = Hash.new) -> String (18207.0)

このメソッドは一つの Array オブジェクトを CSV 文字列に変換するためのショートカットです。 複数行のCSVを扱う際はCSV#<<を使うとより高速です。

...nil でない値を用いて出力の
エンコーディングを推測します。

@param row 文字列の配列を指定します。

@param options CSV.new のオプションと同じオプションを指定できます。
:encoding というキーを使用すると出力のエ...
...コーディングを指定することができます。
:row_sep というキーの値には $/ がセットされます。

//emlist[例][ruby]{
require "csv"

taro = ['1', 'taro', 'tanaka', '20']
CSV.generate_line(taro, col_sep: '|') # => "1|taro|tanaka|20\n"
//}

@see CSV.new...

Array#to_csv(**options) -> String (128.0)

CSV.generate_line(self, options) と同様です。

...CSV.generate_line(self, options) と同様です。

Array オブジェクトを 1 行の CSV 文字列に変換するためのショートカットです。

@param options CSV.generate_line と同様のオプションを指定します。

//emlist[][ruby]{
require 'csv'

p [1, 'Matz', :Ruby, Dat...
...e.new(1965, 4, 14)].to_csv # => "1,Matz,Ruby,1965-04-14\n"
p [1, 'Matz', :Ruby, Date.new(1965, 4, 14)].to_csv(col_sep: ' ', row_sep: "\r\n") # => "1 Matz Ruby 1965-04-14\r\n"
//}


@see CSV.generate_line...
.../emlist[][ruby]{
require 'csv'

puts [1, nil].to_csv # => 1,
puts [1, nil].to_csv(write_nil_value: "N/A") # => 1,N/A
puts [2, ""].to_csv # => 2,""
puts [2, ""].to_csv(write_empty_value: "BLANK") # => 2,BLANK
//}

@see CSV.generate_line...

CSV (30.0)

このクラスは 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") do |row|
p row
end
# => ["Ruby", "1995"]
# ["Rust", "2...
...<< %w{my data here} } # to $stderr
//}

=== CSV と文字エンコーディング (M17n or Multilingualization)

This new CSV parser is m17n savvy. The parser works in the Encoding of the IO
or String object being read from or written to. Your data is never transcoded
(unless you ask Ruby to tran...
...is not ASCII compatible. There's no existing data for CSV to use to
prepare itself and thus you will probably need to manually specify the desired
Encoding for most of those cases. It will try to guess using the fields in a
row of output though, when using CSV::generate_line() or Array#to_csv()....