るりまサーチ

最速Rubyリファレンスマニュアル検索!
252件ヒット [101-200件を表示] (0.024秒)

別のキーワード

  1. string []=
  2. string []
  3. string slice
  4. string slice!
  5. string gsub

クラス

キーワード

検索結果

<< < 1 2 3 > >>

Array#to_csv(**options) -> String (104.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...
...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"
//}

Ruby 3.0 (CSV 3.1.9) から、次のオプションが使えるようになりました...
.../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#col_sep -> String (104.0)

カラム区切り文字列として使用する文字列を返します。

..."csv"

users =<<-EOS
id|first name|last name|age
1|taro|tanaka|20
2|jiro|suzuki|18
3|ami|sato|19
4|yumi|adachi|21
EOS

csv
= CSV.new(users, headers: true, col_sep: "|")
csv
.col_sep # => "|"
csv
.first.to_a # => [["id", "1"], ["first name", "taro"], ["last name", "tanaka"], ["age", "20"]]

csv
= CSV....
...new(users, headers: true)
csv
.col_sep # => ","
csv
.first.to_a # => [["id|first name|last name|age", "1|taro|tanaka|20"]]
//}

@see CSV.new...

CSV#inspect -> String (104.0)

ASCII 互換文字列で自身の情報を表したものを返します。

...ASCII 互換文字列で自身の情報を表したものを返します。

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

csv
= CSV.new("header1,header2\nrow1_1,row1_2")
csv
.inspect # => "<#CSV io_type:StringIO encoding:UTF-8 lineno:0 col_sep:\",\" row_sep:\"\\n\" quote_char:\"\\\"\">"
//}...

CSV#path -> String (104.0)

IO#path に委譲します。

IO#path に委譲します。


@see IO#path

CSV#quote_char -> String (104.0)

フィールドをクオートするのに使用する文字列を返します。

...フィールドをクオートするのに使用する文字列を返します。

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

csv
= CSV.new("header1,header2\nrow1_1,row1_2", quote_char: "'")
csv
.quote_char # => "'"
//}

@see CSV.new...

絞り込み条件を変える

CSV#row_sep -> String (104.0)

行区切り文字列として使用する文字列を返します。

...行区切り文字列として使用する文字列を返します。

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

csv
= CSV.new("header1,header2|row1_1,row1_2", row_sep: "|")
csv
.row_sep # => "|"
csv
.read # => [["header1", "header2"], ["row1_1", "row1_2"]]
//}

@see CSV.new...

CSV::FieldInfo#header -> String | nil (104.0)

利用可能な場合はヘッダを表す文字列を返します。

...返します。

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

csv
= CSV.new("date1,date2\n2018-07-09,2018-07-10", headers: true)
csv
.convert do |field,field_info|
p field_info.header
Date.parse(field)
end
p csv.first

# => "date1"
# => "date2"
# => #<CSV::Row "date1":#<Date: 2018-07-09 ((2458309j,0s,0n),...

CSV::Row#inspect -> String (104.0)

ASCII 互換であるエンコーディングの文字列で自身の情報を返します。

...ASCII 互換であるエンコーディングの文字列で自身の情報を返します。

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

row = CSV::Row.new(["header1", "header2", "header1"], [1, 2, 3])
row.inspect # => "#<CSV::Row \"header1\":1 \"header2\":2 \"header1\":3>"
//}...

CSV::Table#inspect -> String (104.0)

モードとサイズを US-ASCII な文字列で返します。

...モードとサイズを US-ASCII な文字列で返します。

//emlist[][ruby]{
require 'csv'
csv
= CSV.new("a,b,c\n1,2,3", headers: true)
table = csv.read
p table.inspect # => "#<CSV::Table mode:col_or_row row_count:2>"
//}...
<< < 1 2 3 > >>