-
Notifications
You must be signed in to change notification settings - Fork 5
/
mailbox.rb
52 lines (37 loc) · 1018 Bytes
/
mailbox.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class Mailbox
def initialize(owner)
@owner = owner
@emails = []
end
# or attr_reader :owner, instead of the def below
def owner
@owner
end
def capitalize_mail(name)
name.capitalize
end
def emails
@emails
end
#methods retur the last line of code in the method
end
#Email class should have @from and @subject, @body - those are strings and @headers (hash)
class Email
def initialize(from, subject, body, headers)
@from = from
@subject = subject
@body = body
@headers = headers
end
attr_reader :from, :subject, :body, :headers
def header(key)
@headers[key.capitalize]
end
end
anne = Mailbox.new("Anne")
puts anne # in terminal, you'll see the number of a new object
private_email = Email.new("[email protected]", "how are you?", "hey Anne, wanna go for a drink tonight?", {"to" => "[email protected]",
"picture" => "smile"})
work_email = Email.new("[email protected]", "hi", "hello there!", {})
anne.emails << private_email # adding private_email to the an empty array
puts anne.emails