Skip to content

Instantly share code, notes, and snippets.

@apneadiving
Created November 4, 2012 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save apneadiving/4011385 to your computer and use it in GitHub Desktop.
Save apneadiving/4011385 to your computer and use it in GitHub Desktop.
quizz
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
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