Skip to content

Instantly share code, notes, and snippets.

@cheeyeo
Created November 2, 2010 11:25
Show Gist options
  • Save cheeyeo/659502 to your computer and use it in GitHub Desktop.
Save cheeyeo/659502 to your computer and use it in GitHub Desktop.
Report class refactored to use Template pattern
class Report
def initialize
@title = 'My Report'
@text = ['Lorem’, ‘Ipsum']
end
end
def output_report
output_start
output_head
output_body_start
output_body
output_body_end
output_end
end
def output_body
@text.each do |line|
output_line(line)
end
end
def output_start raise 'Called abstract method: output_start'
end
def output_head raise 'Called abstract method: output_head'
end
def output_body_start raise 'Called abstract method: output_body_start'
end
def output_line(line) raise 'Called abstract method: output_line'
end
def output_body_end raise 'Called abstract method: output_body_end'
end
def output_end raise 'Called abstract method: output_end'
end
end # end Report Class
@alassiter
Copy link

It looks like the Report class is ended just after the initialize method. I assume that all of the methods should be inside the Report class?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment