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 HTMLFormatter = lambda do |context| puts '' puts ' ' puts ' ' puts " #{context.title}" puts ' ' puts ' ' context.text.each{|line| puts("

#{line}

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