るりまサーチ

最速Rubyリファレンスマニュアル検索!
24件ヒット [1-24件を表示] (0.099秒)
トップページ > クエリ:ruby[x] > クエリ:Ruby[x] > 種類:インスタンスメソッド[x] > クエリ:r[x] > クエリ:each[x] > クラス:CSV::Table[x]

別のキーワード

  1. rbconfig ruby
  2. fiddle ruby_free
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

検索結果

CSV::Table#each {|row| ... } -> self (18240.0)

デフォルトのミックスモードかロウモードでは、行単位で繰り返します。カラ ムモードでは、ブロックに列名と対応する値の配列を与え、列単位で繰り返し ます。

...ード][ruby]{
r
equire "csv"

r
ow1 = CSV::Row.new(["header1", "header2"], ["row1_1", "row1_2"])
r
ow2 = CSV::Row.new(["header1", "header2"], ["row2_1", "row2_2"])
r
ow3 = CSV::Row.new(["header1", "header2"], ["row3_1", "row3_2"])
table = CSV::Table.new([row1, row2, row3])
table.each { |row| p row }

#...
...SV::Row "header1":"row1_1" "header2":"row1_2">
# => #<CSV::Row "header1":"row2_1" "header2":"row2_2">
# => #<CSV::Row "header1":"row3_1" "header2":"row3_2">
//}

//emlist[例 カラムモード][ruby]{
r
equire "csv"

r
ow1 = CSV::Row.new(["header1", "header2"], ["row1_1", "row1_2"])
r
ow2 = CSV::Row.n...
...r1", "header2"], ["row2_1", "row2_2"])
r
ow3 = CSV::Row.new(["header1", "header2"], ["row3_1", "row3_2"])
table = CSV::Table.new([row1, row2, row3])
table.by_col!
table.each { |column_name, values| print column_name, values, "\n" }

# => header1["row1_1", "row2_1", "row3_1"]
# => header2["row1_2", "r...

CSV::Table#push(*rows) -> self (132.0)

複数の行を追加するためのショートカットです。

...t[][ruby]{
r
ows.each {|row| self << row }
//}

@param rows CSV::Row のインスタンスか配列を指定します。

//emlist[例][ruby]{
r
equire 'csv'
csv = CSV.new("a,b,c\n1,2,3", headers: true)
table = csv.read
r
ows = [
CSV::Row.new(table.headers, [4, 5, 6]),
[7, 8, 9]
]

table.push(*rows...
...)
p table[0..2]
# => [#<CSV::Row "a":"1" "b":"2" "c":"3">, #<CSV::Row "a":4 "b":5 "c":6>, #<CSV::Row "a":7 "b":8 "c":9>]
//}

@see CSV::Table#<<...