168件ヒット
[1-100件を表示]
(0.120秒)
別のキーワード
クラス
- CSV (24)
-
CSV
:: Row (12) -
CSV
:: Table (36) - Matrix (96)
キーワード
-
each
_ with _ index (24) -
find
_ index (36) -
force
_ quotes? (12) - index (36)
- push (12)
検索結果
先頭5件
-
CSV
:: Row # each {|header , field| . . . } -> self (21132.0) -
与えられたブロックにヘッダとフィールドの組を渡して評価します。
...ます。
@return メソッドチェーンのために自身を返します。
//emlist[例][ruby]{
require "csv"
row = CSV::Row.new(["header1", "header2", "header3", "header4"], [1, 2, 3, 4])
row.each { |header, field| puts "#{header} - #{field}" }
# => header1 - 1
# => header2 - 2
# => header3... -
CSV
:: Table # each {|row| . . . } -> self (18510.0) -
デフォルトのミックスモードかロウモードでは、行単位で繰り返します。カラ ムモードでは、ブロックに列名と対応する値の配列を与え、列単位で繰り返し ます。
...ド][ruby]{
require "csv"
row1 = CSV::Row.new(["header1", "header2"], ["row1_1", "row1_2"])
row2 = CSV::Row.new(["header1", "header2"], ["row2_1", "row2_2"])
row3 = CSV::Row.new(["header1", "header2"], ["row3_1", "row3_2"])
table = CSV::Table.new([row1, row2, row3])
table.each { |row| p row }
# =>......V::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]{
require "csv"
row1 = CSV::Row.new(["header1", "header2"], ["row1_1", "row1_2"])
row2 = CSV::Row.ne......, ["row2_1", "row2_2"])
row3 = 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", "row2_2", "row3_2... -
CSV
:: Table # each {|column _ name , values| . . . } -> self (18410.0) -
デフォルトのミックスモードかロウモードでは、行単位で繰り返します。カラ ムモードでは、ブロックに列名と対応する値の配列を与え、列単位で繰り返し ます。
...ド][ruby]{
require "csv"
row1 = CSV::Row.new(["header1", "header2"], ["row1_1", "row1_2"])
row2 = CSV::Row.new(["header1", "header2"], ["row2_1", "row2_2"])
row3 = CSV::Row.new(["header1", "header2"], ["row3_1", "row3_2"])
table = CSV::Table.new([row1, row2, row3])
table.each { |row| p row }
# =>......V::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]{
require "csv"
row1 = CSV::Row.new(["header1", "header2"], ["row1_1", "row1_2"])
row2 = CSV::Row.ne......, ["row2_1", "row2_2"])
row3 = 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", "row2_2", "row3_2... -
CSV
# each {|row| . . . } -> nil (18275.0) -
各行に対してブロックを評価します。
...][ruby]{
require "csv"
users = <<CSV
id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
3,ami,sato,19
4,yumi,adachi,21
CSV
csv = CSV.new(users, headers: true)
csv.each do |row|
p row
end
# => #<CSV::Row "id":"1" "first name":"taro" "last name":"tanaka" "age":"20">
# => #<CSV::Row "id"......name":"suzuki" "age":"18">
# => #<CSV::Row "id":"3" "first name":"ami" "last name":"sato" "age":"19">
# => #<CSV::Row "id":"4" "first name":"yumi" "last name":"adachi" "age":"21">
//}
//emlist[例 CSV.new 時に :header => true を指定しない場合][ruby]{
require "csv"
users = <<CSV
id,first......name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
3,ami,sato,19
4,yumi,adachi,21
CSV
csv = CSV.new(users)
csv.each do |row|
p row
end
# => ["id", "first name", "last name", "age"]
# => ["1", "taro", "tanaka", "20"]
# => ["2", "jiro", "suzuki", "18"]
# => ["3", "ami", "sato", "19"]
# => ["4",... -
Matrix
# each _ with _ index(which = :all) {|e , row , col| . . . } -> self (6240.0) -
行列の各要素をその位置とともに引数としてブロックを呼び出します。
...ができます。
Matrix#each と同じなのでそちらを参照してください。
ブロックを省略した場合、 Enumerator を返します。
//emlist[例][ruby]{
require 'matrix'
Matrix[ [1,2], [3,4] ].each_with_index do |e, row, col|
puts "#{e} at #{row}, #{col}"
end
# => 1 at......0, 0
# => 2 at 0, 1
# => 3 at 1, 0
# => 4 at 1, 1
//}
@param which どの要素に対してブロックを呼び出すのかを Symbol で指定します
@see Matrix#each... -
Matrix
# each _ with _ index(which = :all) -> Enumerator (6140.0) -
行列の各要素をその位置とともに引数としてブロックを呼び出します。
...ができます。
Matrix#each と同じなのでそちらを参照してください。
ブロックを省略した場合、 Enumerator を返します。
//emlist[例][ruby]{
require 'matrix'
Matrix[ [1,2], [3,4] ].each_with_index do |e, row, col|
puts "#{e} at #{row}, #{col}"
end
# => 1 at......0, 0
# => 2 at 0, 1
# => 3 at 1, 0
# => 4 at 1, 1
//}
@param which どの要素に対してブロックを呼び出すのかを Symbol で指定します
@see Matrix#each... -
CSV
:: Table # push(*rows) -> self (161.0) -
複数の行を追加するためのショートカットです。
...[][ruby]{
rows.each {|row| self << row }
//}
@param rows CSV::Row のインスタンスか配列を指定します。
//emlist[例][ruby]{
require 'csv'
csv = CSV.new("a,b,c\n1,2,3", headers: true)
table = csv.read
rows = [
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#<<... -
CSV
# force _ quotes? -> bool (97.0) -
出力される全てのフィールドがクオートされる場合は、真を返します。
...[ruby]{
require "csv"
rows = [["header1", "header2"], ["row1_1,", "row1_2"]]
result = CSV.generate(force_quotes: false) do |csv|
rows.each { |row| csv << row }
csv.force_quotes? # => false
end
print result
# => header1,header2
# "row1_1,",row1_2
//}
//emlist[例][ruby]{
require "csv"
rows......= [["header1", "header2"], ["row1_1,", "row1_2"]]
result = CSV.generate(force_quotes: true) do |csv|
rows.each { |row| csv << row }
csv.force_quotes? # => true
end
print result
# => true
# => "header1","header2"
# "row1_1,","row1_2"
//}
@see CSV.new... -
Matrix
# find _ index(selector = :all) -> Enumerator (29.0) -
指定した値と一致する要素の位置を [row, column] という配列で返します。 ブロックを与えた場合は各要素を引数としてブロックを呼び出し、 返り値が真であった要素の位置を返します。
...指定した値と一致する要素の位置を [row, column] という配列で返します。
ブロックを与えた場合は各要素を引数としてブロックを呼び出し、
返り値が真であった要素の位置を返します。
複数の位置で値が一致する/ブロック......置を返します。
selector で行列のどの部分を探すかを指定します。この引数の意味は
Matrix#each を参照してください。
//emlist[例][ruby]{
require 'matrix'
Matrix[ [1,2], [3,4] ].index(&:even?) # => [0, 1]
Matrix[ [1,1], [1,1] ].index(1, :strict_lower) # => [1...