Created
December 7, 2015 19:56
-
-
Save octosteve/df142fd81a4d07f86242 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 Drink | |
attr_reader :name, :description, :ingredients | |
def initialize(name, description) | |
@name = name | |
@description = description | |
@ingredients = [] | |
end | |
def add_ingredient(ingredient) | |
@ingredients << ingredient | |
ingredient.add_drink(self) | |
end | |
end | |
class Ingredient | |
attr_reader :name, :drinks | |
def initialize(name) | |
@name = name | |
@drinks = [] | |
end | |
def add_drink(drink) | |
@drinks << drink | |
end | |
end | |
long_island = Drink.new("Long Island Iced Tea", "Take a few of these for a fun night") | |
# ["vodka", "gin", "rum", "tequila", "triple-sec", "lemon juice", "coke"] | |
vodka = Ingredient.new("Vodka") | |
gin = Ingredient.new("Gin") | |
rum = Ingredient.new("Rum") | |
tequila = Ingredient.new("Tequila") | |
triple_sec = Ingredient.new("Triple Sec") | |
lemon_juice = Ingredient.new("Lemon Juice") | |
coke = Ingredient.new("Coke") | |
long_island.add_ingredient(vodka) | |
long_island.add_ingredient(gin) | |
long_island.add_ingredient(rum) | |
long_island.add_ingredient(tequila) | |
long_island.add_ingredient(triple_sec) | |
long_island.add_ingredient(lemon_juice) | |
long_island.add_ingredient(coke) | |
rum_and_coke = Drink.new("Rum and Coke", "Simple, and delish") | |
rum_and_coke.add_ingredient(rum) | |
rum_and_coke.add_ingredient(coke) | |
rum.drinks | |
require 'pry' | |
binding.pry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment