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

#{line}

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