Class: Contacts::Contact

Inherits:
Object
  • Object
show all
Defined in:
lib/contacts.rb

Overview

An object that represents a single contact

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email, name = nil, username = nil) ⇒ Contact

Returns a new instance of Contact.



11
12
13
14
15
16
# File 'lib/contacts.rb', line 11

def initialize(email, name = nil, username = nil)
  @emails = []
  @emails << email if email
  @name = name
  @username = username
end

Instance Attribute Details

#emailsObject (readonly)

Returns the value of attribute emails.



9
10
11
# File 'lib/contacts.rb', line 9

def emails
  @emails
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/contacts.rb', line 9

def name
  @name
end

#usernameObject (readonly)

Returns the value of attribute username.



9
10
11
# File 'lib/contacts.rb', line 9

def username
  @username
end

Instance Method Details

#emailObject



18
19
20
# File 'lib/contacts.rb', line 18

def email
  @emails.first
end

#inspectObject



22
23
24
# File 'lib/contacts.rb', line 22

def inspect
  %!#<Contacts::Contact "#{name}"#{email ? " (#{email})" : ''}>!
end