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

ruby-changes:24939

From: zzak <ko1@a...>
Date: Thu, 20 Sep 2012 07:10:26 +0900 (JST)
Subject: [ruby-changes:24939] zzak:r36991 (trunk): * lib/csv.rb (Object#CSV, Array#to_csv, String#parse_csv):

zzak	2012-09-20 07:07:44 +0900 (Thu, 20 Sep 2012)

  New Revision: 36991

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36991

  Log:
    * lib/csv.rb (Object#CSV, Array#to_csv, String#parse_csv): 
      Examples and documentation for CSV.
      [Bug #6880] [ruby-core:47218]

  Modified files:
    trunk/ChangeLog
    trunk/lib/csv.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 36990)
+++ ChangeLog	(revision 36991)
@@ -1,3 +1,9 @@
+Thu Sep 20 07:05:00 2012  Zachary Scott  <zzak@r...>
+
+	* lib/csv.rb (Object#CSV, Array#to_csv, String#parse_csv): 
+	  Examples and documentation for CSV.
+	  [Bug #6880] [ruby-core:47218]
+
 Thu Sep 20 00:42:20 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* array.c (take_items), enum.c (enum_zip): raise TypeError at
Index: lib/csv.rb
===================================================================
--- lib/csv.rb	(revision 36990)
+++ lib/csv.rb	(revision 36991)
@@ -2359,20 +2359,41 @@
   end
 end
 
-# Another name for CSV::instance().
+# Passes +args+ to CSV::instance.
+#
+#   CSV("CSV,data").read
+#     #=> [["CSV", "data"]]
+#
+# If a block is given, the instance is passed the block and the return value
+# becomes the return value of the block.
+#
+#   CSV("CSV,data") { |c|
+#     c.read.any? { |a| a.include?("data") }
+#   } #=> true
+#
+#   CSV("CSV,data") { |c|
+#     c.read.any? { |a| a.include?("zombies") }
+#   } #=> false 
+#
 def CSV(*args, &block)
   CSV.instance(*args, &block)
 end
 
-class Array
-  # Equivalent to <tt>CSV::generate_line(self, options)</tt>.
+class Array # :nodoc:
+  # Equivalent to CSV::generate_line(self, options)
+  #
+  #   ["CSV", "data"].to_csv
+  #     #=> "CSV,data\n"
   def to_csv(options = Hash.new)
     CSV.generate_line(self, options)
   end
 end
 
-class String
-  # Equivalent to <tt>CSV::parse_line(self, options)</tt>.
+class String # :nodoc:
+  # Equivalent to CSV::parse_line(self, options)
+  #
+  #   "CSV,data".parse_csv
+  #     #=> ["CSV", "data"]
   def parse_csv(options = Hash.new)
     CSV.parse_line(self, options)
   end

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

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