Ruby 2.3.0 リファレンスマニュアル > ライブラリ一覧 > csvライブラリ > CSV::Tableクラス > by_row!

instance method CSV::Table#by_row!

by_row! -> self[permalink][rdoc]

自身をロウモードに変更します。

再びモードが変更されるまで、いくつかのメソッドは行単位で動きます。

[RETURN]
必ず自身を返すので安全にメソッドチェーンできます。


require "csv"

row1 = CSV::Row.new(["header1", "header2"], ["row1_1", "row1_2"])
row2 = CSV::Row.new(["header1", "header2"], ["row2_1", "row2_2"])
table = CSV::Table.new([row1, row2])
table         # => #<CSV::Table mode:col_or_row row_count:3>
table.by_row!
table         # => #<CSV::Table mode:row row_count:3>
table[0] # => #<CSV::Row "header1":"row1_1" "header2":"row1_2">
table[1] # => #<CSV::Row "header1":"row2_1" "header2":"row2_2">