Skip to content

Instantly share code, notes, and snippets.

@takaheraw
Created March 6, 2012 13:28
Show Gist options
  • Save takaheraw/1986275 to your computer and use it in GitHub Desktop.
Save takaheraw/1986275 to your computer and use it in GitHub Desktop.
#!/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