A small service builds an attachment summary for emails and returns it to the calling code.
Mailbox#build_index(emails) accepts an array of email hashes.:id, :subject, and :attachments.:attachments must be an empty array.mailbox = Mailbox.new
emails = [
{ id: 1, subject: "A", attachments: ["invoice.pdf"] },
{ id: 2, subject: "B" }
]
index = mailbox.build_index(emails)
index[1][:attachments] << "note.txt"
p index
p emails
emails array must remain unchanged after the call.ruby without additional frameworksThread execution and must not rely on a Fiber schedulerUse line comments to explain the problem, its impact, the fix and how to test it.