Created
March 6, 2012 13:28
-
-
Save takaheraw/1986275 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# coding: utf-8 | |
class Report | |
attr_reader :title, :text | |
attr_accessor :formatter | |
def initialize(&formatter) | |
@title = "月次報告" | |
@text = ["順調","最高の調子"] | |
@formatter = formatter | |
end | |
def output_report | |
@formatter.call(self) | |
end | |
end | |
HTML_FORMATTER = lambda do |context| | |
puts "<html>" | |
puts "<head>" | |
puts "<title>#{context.title}</title>" | |
puts "</head>" | |
puts "<body>" | |
context.text.each do |line| | |
puts "<p>#{line}</p>" | |
end | |
puts "</body>" | |
puts "</html>" | |
end | |
report = Report.new &HTML_FORMATTER | |
report.output_report | |
report = Report.new do |context| | |
puts "*****#{context.title}*****" | |
context.text.each do |line| | |
puts line | |
end | |
end | |
report.output_report |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment