Skip to content

Commit

Permalink
doc CSV.parse: Add BOM handling (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
JunichiIto committed May 17, 2024
1 parent 73b877d commit 4e19f3d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,23 @@ def open(filename, mode="r", **options)
# Raises an exception if the argument is not a \String object or \IO object:
# # Raises NoMethodError (undefined method `close' for :foo:Symbol)
# CSV.parse(:foo)
#
# ---
#
# Please make sure if your text contains \BOM or not. CSV.parse will not remove
# \BOM automatically. You might want to remove \BOM before calling CSV.parse :
# # remove BOM on calling File.open
# File.open(path, encoding: 'bom|utf-8') do |file|
# CSV.parse(file, headers: true) do |row|
# # you can get value by column name because BOM is removed
# p row['Name']
# end
# end
#
# Output:
# # "foo"
# # "bar"
# # "baz"
def parse(str, **options, &block)
csv = new(str, **options)

Expand Down

0 comments on commit 4e19f3d

Please sign in to comment.