instance method CSV#force_quotes?

force_quotes? -> bool[permalink][rdoc]

出力される全てのフィールドがクオートされる場合は、真を返します。



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


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_ALSO] CSV.new