Class: Contacts::Contact
- Inherits:
-
Object
- Object
- Contacts::Contact
- Defined in:
- lib/contacts.rb
Overview
An object that represents a single contact
Instance Attribute Summary collapse
-
#emails ⇒ Object
readonly
Returns the value of attribute emails.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #email ⇒ Object
-
#initialize(email, name = nil, username = nil) ⇒ Contact
constructor
A new instance of Contact.
- #inspect ⇒ Object
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
#emails ⇒ Object (readonly)
Returns the value of attribute emails.
9 10 11 |
# File 'lib/contacts.rb', line 9 def emails @emails end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/contacts.rb', line 9 def name @name end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
9 10 11 |
# File 'lib/contacts.rb', line 9 def username @username end |
Instance Method Details
#email ⇒ Object
18 19 20 |
# File 'lib/contacts.rb', line 18 def email @emails.first end |
#inspect ⇒ Object
22 23 24 |
# File 'lib/contacts.rb', line 22 def inspect %!#<Contacts::Contact "#{name}"#{email ? " (#{email})" : ''}>! end |