Skip to content

Instantly share code, notes, and snippets.

@andersonleite
Created October 25, 2009 14:53
Show Gist options
  • Save andersonleite/218101 to your computer and use it in GitHub Desktop.
Save andersonleite/218101 to your computer and use it in GitHub Desktop.
class Relatorio
attr_reader :titulo, :texto
attr_accessor :formatter
def initialize(&formatter)
@titulo = 'Relatorio Mensal'
@texto = [ 'Gastos do mês', 'contas, e mais contas.' ]
@formatter = formatter
end
def imprime_relatorio
@formatter.call( self )
end
end
HTML_FORMATTER = lambda do |context|
puts('<html>')
puts(' <head>')
puts(" <title>#{context.titulo}</title>")
puts(' </head>')
puts(' <body>')
context.texto.each do |line|
puts(" <p>#{line}</p>" )
end
puts(' </body>')
puts('</html>')
end
relatorio = Relatorio.new &HTML_FORMATTER
relatorio.imprime_relatorio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment