[前][次][番号順一覧][スレッド一覧]

ruby-changes:62305

From: Burdette <ko1@a...>
Date: Mon, 20 Jul 2020 03:35:56 +0900 (JST)
Subject: [ruby-changes:62305] 920a16893a (master): [ruby/csv] RDoc for parse_line (adds headers examples) (#143)

https://git.ruby-lang.org/ruby.git/commit/?id=920a16893a

From 920a16893ad5b76bcb357d45f2c0b9d91d09268e Mon Sep 17 00:00:00 2001
From: Burdette Lamar <BurdetteLamar@Y...>
Date: Thu, 18 Jun 2020 17:02:02 -0500
Subject: [ruby/csv] RDoc for parse_line (adds headers examples) (#143)

* RDoc for parse_line (adds headers examples)

* RDoc for parse_line (adds headers examples)
https://github.com/ruby/csv/commit/a161be928e

diff --git a/lib/csv.rb b/lib/csv.rb
index 88bfcd8..6e71766 100644
--- a/lib/csv.rb
+++ b/lib/csv.rb
@@ -1288,35 +1288,59 @@ class CSV https://github.com/ruby/ruby/blob/trunk/lib/csv.rb#L1288
     end
 
     # :call-seq:
-    #   CSV.parse_line(string)
-    #   CSV.parse_line(io)
-    #   CSV.parse_line(string, **options)
-    #   CSV.parse_line(io, **options)
-    #
-    # Returns the new \Array created by parsing the first line of +string+ or +io+
+    #   CSV.parse_line(string) -> new_array or nil
+    #   CSV.parse_line(io) -> new_array or nil
+    #   CSV.parse_line(string, **options) -> new_array or nil
+    #   CSV.parse_line(io, **options) -> new_array or nil
+    #   CSV.parse_line(string, headers: true, **options) -> csv_row or nil
+    #   CSV.parse_line(io, headers: true, **options) -> csv_row or nil
+    #
+    # Returns the data created by parsing the first line of +string+ or +io+
     # using the specified +options+.
     #
     # - Argument +string+ should be a \String object;
     #   it will be put into a new StringIO object positioned at the beginning.
     # :include: ../doc/argument_io.rdoc
-    #   To position at the end, for appending, use method CSV.generate.
-    #   For any other positioning, pass a preset \StringIO object instead.
     # - Argument +options+: see {Options for Parsing}[#class-CSV-label-Options+for+Parsing]
     #
-    # ---
-    # Returns data from the first line from a String object:
-    #   CSV.parse_line('foo,0') # => ["foo", "0"]
+    # ====== Without Option +headers+
     #
-    # Returns data from the first line from a File object:
-    #   File.write('t.csv', 'foo,0')
-    #   CSV.parse_line(File.open('t.csv')) # => ["foo", "0"]
+    # Without option +headers+, returns the first row as a new \Array.
     #
-    # Ignores lines after the first:
-    #   CSV.parse_line("foo,0\nbar,1\nbaz,2") # => ["foo", "0"]
+    # These examples assume prior execution of:
+    #   string = "foo,0\nbar,1\nbaz,2\n"
+    #   path = 't.csv'
+    #   File.write(path, string)
+    #
+    # Parse the first line from a \String object:
+    #   CSV.parse_line(string) # => ["foo", "0"]
+    #
+    # Parse the first line from a File object:
+    #   File.open(path) do |file|
+    #     CSV.parse_line(file) # => ["foo", "0"]
+    #   end # => ["foo", "0"]
     #
     # Returns +nil+ if the argument is an empty \String:
     #   CSV.parse_line('') # => nil
     #
+    # ====== With Option +headers+
+    #
+    # With {option +headers+}[#class-CSV-label-Option+headers],
+    # returns the first row as a CSV::Row object.
+    #
+    # These examples assume prior execution of:
+    #   string = "Name,Count\nfoo,0\nbar,1\nbaz,2\n"
+    #   path = 't.csv'
+    #   File.write(path, string)
+    #
+    # Parse the first line from a \String object:
+    #   CSV.parse_line(string, headers: true) # => #<CSV::Row "Name":"foo" "Count":"0">
+    #
+    # Parse the first line from a File object:
+    #   File.open(path) do |file|
+    #     CSV.parse_line(file, headers: true)
+    #   end # => #<CSV::Row "Name":"foo" "Count":"0">
+    #
     # ---
     #
     # Raises an exception if the argument is +nil+:
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]