The Mailbox Class
Exercise 11.1
In a new file mailbox-1.rb Write a class that has a name and emails attribute. Make it so that the these attributes can be populated through the initialize method (name being a string, and emails being an array of Email instances).
The following code
class Email# your class from the last exerciseendclass Mailbox# fill in this class bodyendemails = [Email.new("Homework this week", { :date => "2014-12-01", :from => "Ferdous" }),Email.new("Keep on coding! :)", { :date => "2014-12-01", :from => "Dajana" }),Email.new("Re: Homework this week", { :date => "2014-12-02", :from => "Ariane" })]mailbox = Mailbox.new("Ruby Study Group", emails)mailbox.emails.each do |email|puts "Date: #{email.date}"puts "From: #{email.from}"puts "Subject: #{email.subject}"putsend
should then output the following:
Date: 2014-12-01From: FerdousSubject: Homework this weekDate: 2014-12-01From: DajanaSubject: Keep on coding! :)Date: 2014-12-02From: ArianneSubject: Re: Homework this week
当前内容版权归 rubymonstas 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 rubymonstas .
