Skip to content

Commit cc76ffb

Browse files
authored
docs: fix example in Recipe: Capture Unconverted Fields (#276)
I've fixed the example in `Recipe: Capture Unconverted Fields`. https://ruby.github.io/csv/doc/csv/recipes/parsing_rdoc.html#label-Recipe-3A+Capture+Unconverted+Fields `parsed` is wrong: header row is missing and the values should be integers. ``` $ ruby -v ruby 3.2.1 (2023-02-08 revision 31819e82c8) [x86_64-darwin21] $ cat unconverted_fields.rb require "csv" source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" parsed = CSV.parse(source, converters: :integer, unconverted_fields: true) p parsed parsed.each {|row| p row.unconverted_fields } $ ruby unconverted_fields.rb [["Name", "Value"], ["foo", 0], ["bar", 1], ["baz", 2]] ["Name", "Value"] ["foo", "0"] ["bar", "1"] ["baz", "2"] ```
1 parent 04862cc commit cc76ffb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

doc/csv/recipes/parsing.rdoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ Apply multiple header converters by defining and registering a custom header con
520520
To capture unconverted field values, use option +:unconverted_fields+:
521521
source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n"
522522
parsed = CSV.parse(source, converters: :integer, unconverted_fields: true)
523-
parsed # => [["foo", "0"], ["bar", "1"], ["baz", "2"]]
523+
parsed # => [["Name", "Value"], ["foo", 0], ["bar", 1], ["baz", 2]]
524524
parsed.each {|row| p row.unconverted_fields }
525525
Output:
526526
["Name", "Value"]

0 commit comments

Comments
 (0)