@taxes << Irpj.new(value) @taxes << Pis.new(value) end def print @taxes.each do |tax| puts tax.name puts "Devido: R$#{tax.due_value}" puts "Retido: R$#{tax.retained_value}" end end end
when Note print_note printable when Report print_report printable end end private def print_document(printable) # ... end def print_note(printable) # ... end def print_report(printable) # ... end end
@printables << printable end def print(printable) puts "Printing a #{printable.class.name}..." end def print_all @printables.each { |p| print p } end end