Skip to content

Instantly share code, notes, and snippets.

@alvin2ye
Created October 27, 2009 05:32
Show Gist options
  • Save alvin2ye/219341 to your computer and use it in GitHub Desktop.
Save alvin2ye/219341 to your computer and use it in GitHub Desktop.
TempleteMethod
# TempleteMethod
class Report
attr_accessor :title, :content
def initialize
@title = "I am a title"
@content = "I am a content"
hook_process
end
def hook_process ; end
def output
raise 'Called abstract method : output'
end
end
class HTMLReport < Report
def output_title
puts "<head><title> #{title} </title></head>"
end
def hook_process
@content = "<div> \r\n #{content} \r\n</div>"
end
def output_content
puts "<body> #{content} </body>"
end
def output
puts "<html>"
output_title
output_content
puts "</html>"
end
end
class PlainTextReport < Report
def output_title
puts title
end
def output_content
puts content
end
def output
output_title
output_content
end
end
HTMLReport.new.output
# PlainTextReport.new.output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment