class SalesReport def initialize(data) @data = data end def generate_report report = "売上レポート\n" @data.each do |item| report += "#{item[:name]}: #{item[:sales]}円\n" end report end def display puts generate_report end def save_to_file(filename) File.write(filename, generate_report) endend
class Order def initialize(items) @items = items end def process_order # 注文処理のロジック puts "注文が処理されました" end def generate_invoice invoice = "請求書\n" total = 0 @items.each do |item| invoice += "#{item[:name]}: #{item[:price]}円\n" total += item[:price] end invoice += "合計: #{total}円" invoice endend