Last active
August 29, 2015 14:09
-
-
Save tylerdooling/ab27da936d3f3e2e1699 to your computer and use it in GitHub Desktop.
Eastward HO!
This file contains hidden or 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 Person | |
attr_reader :address | |
def display_address(template = Template.new) | |
address.display(template) | |
self | |
end | |
end | |
class Address | |
def display(template) | |
address_data_structure = to_data(template.address_structure) | |
template.display_address(address_data_structure) | |
self | |
end | |
private | |
def to_data(structure) | |
structure.keys.inject({}) { |hash, key| hash.store(key, send(key)) } | |
end | |
end | |
class Template | |
def address_structure | |
Hash[[ :street, :city, :state, :postal_code ].map { |k| [k, nil] }] | |
end | |
def display_address(address_data_structure) | |
# do stuff to format address_data_structure... | |
STOUT.puts formatted_address | |
self | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment