Created
November 4, 2012 11:11
-
-
Save apneadiving/4011385 to your computer and use it in GitHub Desktop.
quizz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserInfo | |
attr_accessor :contact | |
def initialize(contact = nil) | |
self.contact = contact || NullContact.new | |
end | |
def contact_name | |
contact.name | |
end | |
def contact_mail | |
contact.mail | |
end | |
def contact_phone | |
contact.phone | |
end | |
end | |
class NullContact | |
def name | |
"no name" | |
end | |
def mail | |
"no mail" | |
end | |
def phone | |
"no phone" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserInfo | |
attr_accessor :contact | |
def initialize(contact = nil) | |
self.contact = contact | |
end | |
def contact_name | |
if contact | |
contact.name | |
else | |
"no name" | |
end | |
end | |
def contact_mail | |
if contact | |
contact.mail | |
else | |
"no mail" | |
end | |
end | |
def contact_phone | |
if contact | |
contact.phone | |
else | |
"no phone" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment