diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-08-26 14:54:17 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2022-09-03 15:54:07 +0900 |
commit | eed5970b6477910f11630458bb4649c0b94cd4fb (patch) | |
tree | 7534a3b1fe944287deabeb799a0f4b88df3dc745 /lib | |
parent | cd0c2a67c482c441ac7f0a07c0f81573d6b6072f (diff) |
Merge csv-3.2.5
Diffstat (limited to 'lib')
-rw-r--r-- | lib/csv.rb | 40 | ||||
-rw-r--r-- | lib/csv/version.rb | 2 |
2 files changed, 41 insertions, 1 deletions
diff --git a/lib/csv.rb b/lib/csv.rb index 20cfda4b41..170ab04c24 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -1465,6 +1465,46 @@ class CSV (new(str, **options) << row).string end + # :call-seq: + # CSV.generate_lines(rows) + # CSV.generate_lines(rows, **options) + # + # Returns the \String created by generating \CSV from + # using the specified +options+. + # + # Argument +rows+ must be an \Array of row. Row is \Array of \String or \CSV::Row. + # + # Special options: + # * Option <tt>:row_sep</tt> defaults to <tt>"\n"</tt> on Ruby 3.0 or later + # and <tt>$INPUT_RECORD_SEPARATOR</tt> (<tt>$/</tt>) otherwise.: + # $INPUT_RECORD_SEPARATOR # => "\n" + # * This method accepts an additional option, <tt>:encoding</tt>, which sets the base + # Encoding for the output. This method will try to guess your Encoding from + # the first non-+nil+ field in +row+, if possible, but you may need to use + # this parameter as a backup plan. + # + # For other +options+, + # see {Options for Generating}[#class-CSV-label-Options+for+Generating]. + # + # --- + # + # Returns the \String generated from an + # CSV.generate_lines(['foo', '0'], ['bar', '1'], ['baz', '2']) # => "foo,0\nbar,1\nbaz.2\n" + # + # --- + # + # Raises an exception + # # Raises NoMethodError (undefined method `find' for :foo:Symbol) + # CSV.generate_lines(:foo) + # + def generate_lines(rows, **options) + self.generate(**options) do |csv| + rows.each do |row| + csv << row + end + end + end + # # :call-seq: # open(file_path, mode = "rb", **options ) -> new_csv diff --git a/lib/csv/version.rb b/lib/csv/version.rb index eaddde9a23..ca16064a89 100644 --- a/lib/csv/version.rb +++ b/lib/csv/version.rb @@ -2,5 +2,5 @@ class CSV # The version of the installed library. - VERSION = "3.2.4" + VERSION = "3.2.5" end |