Skip to content

Instantly share code, notes, and snippets.

@tylerdooling
Last active August 29, 2015 14:09
Show Gist options
  • Save tylerdooling/ab27da936d3f3e2e1699 to your computer and use it in GitHub Desktop.
Save tylerdooling/ab27da936d3f3e2e1699 to your computer and use it in GitHub Desktop.
Eastward HO!
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