class Report attr_reader :title, :text attr_accessor :formatter def initialize(formatter) @title = '月次報告' @text = ['順調','さいこ〜〜〜'] @fomatter = formatter end def output_report @fomatter.output_report(@title, @text) end end class Formatter def output_report(title,text) raise 'Abstract method called.' end end class HTMLFormatter < Formatter def output_report(title,text) puts '' puts ' ' puts ' ' puts " #{title}" puts ' ' puts ' ' text.each{|line| puts("

#{line}

") } puts ' ' puts '' end end class PlainTextFormatter < Formatter def output_report(title,text) puts " ***#{title}***" text.each{|line| puts(" #{line}\n") } end end report = Report.new(HTMLFormatter.new) report.output_report report = Report.new(PlainTextFormatter.new) report.output_report report = Report.new(Formatter.new) report.output_report