Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class ResponseWriter
def write(customer, serialize, writer)
writer.write(serialize.call(customer))
end
end
customer = Customer.new("Mr", "Jason", "Gorman")
writer = ResponseWriter.new
writer.write(customer, lambda {|c| HtmlSerializer.new().serialize(c)}, ConsoleWriter.new)
writer.write(customer, lambda {|c| XmlSerializer.new().serialize(c)}, LogFileWriter.new("C:\test\testlog.txt"))
writer.write(customer, lambda {|c| StringSerializer.new().serialize(c)}, NoSqlWriter.new("mongodb", "localhost", "admin", "password123"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment