# Step 1: Require the CSV module
require 'csv'
# Step 2: Define the data to be written to the CSV file
data = [
['Name', 'Age', 'City'],
['John Doe', 30, 'New York'],
['Jane Smith', 25, 'Los Angeles'],
['Bob Johnson', 35, 'Chicago']
]
# Step 3: Specify the CSV file path
csv_file_path = 'example.csv'
# Step 4: Open the CSV file for writing using the CSV module
CSV.open(csv_file_path, 'w') do |csv|
# Step 5: Write the data to the CSV file row by row
data.each do |row|
csv << row
end
end
# Step 6: Output a success message
puts "CSV file created successfully at #{csv_file_path}"