@@ -1288,35 +1288,59 @@ def parse(str, **options, &block)
1288
1288
end
1289
1289
1290
1290
# :call-seq:
1291
- # CSV.parse_line(string)
1292
- # CSV.parse_line(io)
1293
- # CSV.parse_line(string, **options)
1294
- # CSV.parse_line(io, **options)
1295
- #
1296
- # Returns the new \Array created by parsing the first line of +string+ or +io+
1291
+ # CSV.parse_line(string) -> new_array or nil
1292
+ # CSV.parse_line(io) -> new_array or nil
1293
+ # CSV.parse_line(string, **options) -> new_array or nil
1294
+ # CSV.parse_line(io, **options) -> new_array or nil
1295
+ # CSV.parse_line(string, headers: true, **options) -> csv_row or nil
1296
+ # CSV.parse_line(io, headers: true, **options) -> csv_row or nil
1297
+ #
1298
+ # Returns the data created by parsing the first line of +string+ or +io+
1297
1299
# using the specified +options+.
1298
1300
#
1299
1301
# - Argument +string+ should be a \String object;
1300
1302
# it will be put into a new StringIO object positioned at the beginning.
1301
1303
# :include: ../doc/argument_io.rdoc
1302
- # To position at the end, for appending, use method CSV.generate.
1303
- # For any other positioning, pass a preset \StringIO object instead.
1304
1304
# - Argument +options+: see {Options for Parsing}[#class-CSV-label-Options+for+Parsing]
1305
1305
#
1306
- # ---
1307
- # Returns data from the first line from a String object:
1308
- # CSV.parse_line('foo,0') # => ["foo", "0"]
1306
+ # ====== Without Option +headers+
1309
1307
#
1310
- # Returns data from the first line from a File object:
1311
- # File.write('t.csv', 'foo,0')
1312
- # CSV.parse_line(File.open('t.csv')) # => ["foo", "0"]
1308
+ # Without option +headers+, returns the first row as a new \Array.
1313
1309
#
1314
- # Ignores lines after the first:
1315
- # CSV.parse_line("foo,0\nbar,1\nbaz,2") # => ["foo", "0"]
1310
+ # These examples assume prior execution of:
1311
+ # string = "foo,0\nbar,1\nbaz,2\n"
1312
+ # path = 't.csv'
1313
+ # File.write(path, string)
1314
+ #
1315
+ # Parse the first line from a \String object:
1316
+ # CSV.parse_line(string) # => ["foo", "0"]
1317
+ #
1318
+ # Parse the first line from a File object:
1319
+ # File.open(path) do |file|
1320
+ # CSV.parse_line(file) # => ["foo", "0"]
1321
+ # end # => ["foo", "0"]
1316
1322
#
1317
1323
# Returns +nil+ if the argument is an empty \String:
1318
1324
# CSV.parse_line('') # => nil
1319
1325
#
1326
+ # ====== With Option +headers+
1327
+ #
1328
+ # With {option +headers+}[#class-CSV-label-Option+headers],
1329
+ # returns the first row as a CSV::Row object.
1330
+ #
1331
+ # These examples assume prior execution of:
1332
+ # string = "Name,Count\nfoo,0\nbar,1\nbaz,2\n"
1333
+ # path = 't.csv'
1334
+ # File.write(path, string)
1335
+ #
1336
+ # Parse the first line from a \String object:
1337
+ # CSV.parse_line(string, headers: true) # => #<CSV::Row "Name":"foo" "Count":"0">
1338
+ #
1339
+ # Parse the first line from a File object:
1340
+ # File.open(path) do |file|
1341
+ # CSV.parse_line(file, headers: true)
1342
+ # end # => #<CSV::Row "Name":"foo" "Count":"0">
1343
+ #
1320
1344
# ---
1321
1345
#
1322
1346
# Raises an exception if the argument is +nil+:
0 commit comments