Skip to content

Instantly share code, notes, and snippets.

@bruno-
Last active December 25, 2015 03:09
Show Gist options
  • Save bruno-/6908044 to your computer and use it in GitHub Desktop.
Save bruno-/6908044 to your computer and use it in GitHub Desktop.
class SmsNotifier
# We want to reuse code from this class,
# and we try to do that by using inheritance.
def notify!
# texting magic happens here
end
end
class ReportGenerator < SmsNotifier
# Send text messages when the report is done - no problem
def report_done_hook
notify!
end
end
class ReportArchiver < ActiveRecord::Base
# Oops! this object already has a superclass!
# How do you reuse the code now?
def report_compressed_hook
# notify!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment