Skip to content

Instantly share code, notes, and snippets.

@coderdan
Last active December 25, 2015 15:59
Show Gist options
  • Select an option

  • Save coderdan/7002278 to your computer and use it in GitHub Desktop.

Select an option

Save coderdan/7002278 to your computer and use it in GitHub Desktop.
class Person
attr_writer :job
def job
@job || NoJob.new
end
end
class Job
def title
"CEO"
end
end
class NoJob
def title
raise "Person is unemployed"
end
end
frank = Person.new
frank.job = Job.new
frank.job.title => "CEO"
bum = Person.new
bum.job.title => raises "Person is unemployed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment