mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/csv] CSV(): Add support for Ruby 3 (https://github.com/ruby/csv/pull/215)
The implementation of the `CSV` shortcut method is broken in Ruby 3
for calls that look like this:
```ruby
CSV(write_stream, col_sep: "|", headers: headers, write_headers: true) do |csv|
...
end
```
The above will result in the following error when the `CSV` method attempts to pass
on arguments to `CSV#instance`:
```
ArgumentError: wrong number of arguments (given 2, expected 0..1)
```
The issue is due to the changes in Ruby 3 relating to positional & keyword arguments.
This commit updates the `CSV()` shortcut implementation to work with Ruby 3, and also
updates the documentation for the shortcut method.
310dee45fa
This commit is contained in:
parent
1073975013
commit
8fde54a3b5
Notes:
git
2021-10-24 05:58:03 +09:00
2 changed files with 16 additions and 2 deletions
|
@ -112,4 +112,13 @@ a;b;c
|
|||
assert_equal(CSV.instance,
|
||||
CSV {|csv| csv})
|
||||
end
|
||||
|
||||
def test_instance_shortcut_with_io
|
||||
io = StringIO.new
|
||||
from_instance = CSV.instance(io, col_sep: ";") { |csv| csv << ["a", "b", "c"] }
|
||||
from_shortcut = CSV(io, col_sep: ";") { |csv| csv << ["e", "f", "g"] }
|
||||
|
||||
assert_equal(from_instance, from_shortcut)
|
||||
assert_equal(from_instance.string, "a;b;c\ne;f;g\n")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue