Skip to content

Instantly share code, notes, and snippets.

@spanuska
Created March 31, 2016 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spanuska/0690d4208e8fe1ae0b4add6a39bdf3dc to your computer and use it in GitHub Desktop.
Save spanuska/0690d4208e8fe1ae0b4add6a39bdf3dc to your computer and use it in GitHub Desktop.
Shelf with a dependency-managing wrapper method
class Shelf # without the wrapper
...
def store(book)
# imagine complicated logic here...
intermediate_result = book.storage_requirements / self.capacity
# imagine more complicated logic...
end
end
class Shelf # with wrapper
...
def store(book)
# imagine complicated logic here...
intermediate_result = storage_requirements(book) / capacity
# imagine more complicated logic...
end
def storage_requirements(book)
book.storage_requirements
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment