Skip to content

Instantly share code, notes, and snippets.

@LNA
Last active August 29, 2015 14:15
Show Gist options
  • Save LNA/3fba7a61396c81e5b451 to your computer and use it in GitHub Desktop.
Save LNA/3fba7a61396c81e5b451 to your computer and use it in GitHub Desktop.
Dependency Injection
class BookShelf
def initialize(books, magazines, flowers)
@books = books
@magazines = magazines
@flowers = flowers
end
def find(book)
@books.find(book)
end
def arrange
@flowers.arrange
end
end
class Books
#code
end
class Magazines
#code
end
class Flowers
#code
end
my_books = Books.new
my_magazines = Magazines.new
my_flowers = Flowers.new
my_bookshelf = BookShelf.new(my_books, my_magazines, my_flowers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment