Create a CSV::Table Object
When you parse a file or string using CSV.parse
(with headers = true
) you get a CSV::Table
object in response. This object can be used to read what was in a file or it can be used to create a new file. It is also handy as a potential test object if you want to assume, but omit, file reading in a unit test.
You can create a CSV::Table
one of the following two ways. First, with a file:
Second, with a string, or even better, a HEREDOC:
From here, you can do what you need with it, whether that is using it in a test or writing it to a file.
Last updated