Created
March 23, 2019 13:39
-
-
Save jasongorman/fc19267dcb0fd8345f960a97275eb71a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ResponseWriter | |
def write(customer, serialize, write) | |
write.call(serialize.call(customer)) | |
end | |
end | |
customer = Customer.new("Mr", "Jason", "Gorman") | |
writer = ResponseWriter.new | |
writer.write(customer, method(:to_html), lambda {|o| ConsoleWriter.new().write(o)}) | |
writer.write(customer, method(:to_xml), lambda {|o| LogFileWriter.new("C:\test\testlog.txt").write(o)}) | |
writer.write(customer, method(:to_string), lambda {|o| NoSqlWriter.new( | |
"mongodb", | |
"localhost", | |
"admin", | |
"password123").write(o)}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment