...

/

Solution: Mail Merge Birthday Invitation Cards

Solution: Mail Merge Birthday Invitation Cards

Run the solution and see these newly created files in the command-line interface.

Solution

guest_list = ["Pokkle", "Angela", "Tonpa", "Toby", "Biscuit", "Mito", "Kate", "Renee", "Chloe", "Kelly", "Melody"]

invitation = "Dear {{first_name}},

I am celebrating my 12th Birthday on the 1st of April!
Come celebrate with me!

Where: 42 Greed-Island Street, Yorkshin City
When: 2PM to 5PM
RSVP: 24th of March (0400-000-000 or rsvpjessica@example.com)

Hope to see you there,

Jessica."

guest_list.each do |name|
	named_invitation = invitation.gsub("{{first_name}}", name)
	File.open("./files/#{name.downcase}_invitation.txt", "w").write(named_invitation)
end

puts "\n\nUse ls and cat commands to list and examine the created files."
Generating text files for the birthday invitation cards

Explanation

  • Line 1: An array containing the names of guests is created.

  • Lines 3–14: ...