11. class Relatorio
def generate
output_head
output_body
output_footer
end
def output_head
end
def output_body
end
def output_footer
end
end
12. class Relatorio
def generate
output_head
output_body
output_footer
end
def output_head
end
def output_body
end
def output_footer
end
end
13. class Relatorio
def generate
output_head
Template
output_body
Method
output_footer
end
def output_head
end
def output_body
end
def output_footer
end
end
14. class HTMLRelatorio < Relatorio
def output_head
puts "<html><head>
<title>Relatório HTML</title>
</head>"
end
def output_body
puts "<body>...</body>"
end
def output_footer
puts "</html>"
end
end
15. class HTMLRelatorio < Relatorio
def output_head
puts "<html><head>
<title>Relatório HTML</title>
</head>"
end
def output_body
puts "<body>...</body>"
end
def output_footer
puts "</html>"
end
end
16. class HTMLRelatorio < Relatorio
def output_head
puts "<html><head>
<title>Relatório HTML</title>
</head>"
end
def output_body
puts "<body>...</body>"
end
def output_footer
puts "</html>"
end
end
53. require "observer"
class NotaFiscal
include Observable
@observers.each { pagar
def |o| o.update(object) } if @changed
...
changed
notify_observers(self)
end
end
76. class Pizza
attr_accessor :massa, :molho, :cobertura
end
77. class PizzaBuilder
attr_reader :pizza
def initialize
@pizza = Pizza.new
end
end
78. class CalabresaBuilder < PizzaBuilder
def molho
@pizza.molho = "Tomate"
end
def massa
@pizza.massa = "Pão"
end
def cobertura
@pizza.cobertura = "queijo, calabresa"
end
end
81. class CalabresaBuilder < PizzaBuilder
def molho
@pizza.molho = "Tomate"
self
end
def massa
@pizza.massa = "Pão"
self
end
def cobertura
@pizza.cobertura = "queijo, calabresa"
self
end
end
83. class PizzaBuilder
def method_missing(name, *args)
methods = name.to_s.split("_")
return super(name, *args) unless
methods[1] == "and"
methods.each do |method|
next if method == "and"
send(method)
end
end
end
109. class ContaBancaria
def initialize(saldo)
@saldo = saldo
end
def depositar!(valor)
@saldo += valor
end
def sacar!(valor)
@saldo -= valor
end
def some_method
end
end
110. class ContaBancariaProxy
def initialize(conta_bancaria)
@conta_bancaria = conta_bancaria
end
def depositar!(valor)
@conta_bancaria.depositar! valor
end
def sacar!(valor)
@conta_bancaria .sacar! valor
end
end
112. class ContaBancariaProxy
def initialize(conta_bancaria)
@conta_bancaria = conta_bancaria
end
def depositar!(valor)
@conta_bancaria.depositar! valor
end
def sacar!(valor)
@conta_bancaria .sacar! valor
end
end
113. class ContaBancariaProxy
def initialize(conta_bancaria, owner)
@conta_bancaria = conta_bancaria
@owner = owner
end
protected
def check_access
raise "Illegal Access" unless User. login
== @owner
end
end
114. class ContaBancariaProxy
def depositar!(valor)
check_access
@conta_bancaria.depositar! valor
end
def sacar!(valor)
check_access
@conta_bancaria .sacar! valor
end
end
117. class Coffee
def price
@price
end
def ingredients
@ingredients
end
end
118. class MilkDecorator
def initialize (coffee)
@coffee = coffee
end
def price
coffee.price + 0.5
end
def ingredients
coffee.ingredients + ", Leite"
end
end
119. class MilkDecorator
def initialize (coffee)
@coffee = coffee
end
def price
coffee.price + 0.5
end
def ingredients
coffee.ingredients + ", Leite"
end
end
120. class MilkDecorator
def initialize (coffee)
@coffee = coffee
end
def price
coffee.price + 0.5
end
def ingredients
coffee.ingredients + ", Leite"
end
end
121. class MilkDecorator
def initialize (coffee)
@coffee = coffee
end
def price
coffee.price + 0.5
end
def ingredients
coffee.ingredients + ", Leite"
end
end
127. class ChocolateDecorator
def initialize (coffee)
@coffee = coffee
end
def price
coffee.price + 1.0
end
def ingredients
coffee.ingredients + ", Chocolate"
end
end