-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookbook.rb
109 lines (81 loc) · 2.67 KB
/
cookbook.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
class Cookbook
attr_accessor :title
attr_reader :recipes
def initialize(title)
@title = title
@recipes = []
end
def add_recipe(recipe)
@recipes << recipe #how does this work???
puts "Added a recipe to the collection: #{recipe.title}"
end
def recipe_titles
@recipes.each do |x|
puts x.title
end
end
def recipe_ingredients
@recipes.each do |x|
puts "These are the ingredients for #{x.title}: #{x.ingredients}"
end
end
def print_cookbook
@recipes.each do |x|
puts "The title is #{x.title}."
puts "The ingredients are #{x.ingredients.join(", ")}."
puts "The steps to make are the following:"
puts "1. #{x.steps[0]}"
puts "2. #{x.steps[1]}"
puts "3. #{x.steps[2]}"
end
end
def remove_item(recipe)
puts "The item #{recipe.title} has been deleted!"
@recipes.delete(recipe)
end
end
class Recipe
attr_accessor :title
attr_accessor :ingredients
attr_accessor :steps
def initialize(title, ingredients, steps)
@title = title
@ingredients = ingredients
@steps = steps
end
def print_recipe
puts "The title is #{@title}"
puts "The ingredients are #{@ingredients.join(", ")}."
puts "The steps to make are the following:"
puts "1. #{@steps[0]}"
puts "2. #{@steps[1]}"
puts "3. #{@steps[2]}"
end
def add_hotsauce
@ingredients << "hot sauce"
end
end
# mex_cuisine = Cookbook.new("Mexican Cooking")
# burrito = Recipe.new("Bean Burrito", ["tortilla", "bean"], ["heat beans", "place beans in tortilla", "roll up"])
# puts mex_cuisine.title # Mexican Cooking
# puts burrito.title # Bean Burrito
# p burrito.ingredients # ["tortilla", "bean", "cheese"]
# p burrito.steps # ["heat beans", "heat tortilla", "place beans in tortilla", "sprinkle cheese on top", "roll up"]
# mex_cuisine.title = "Mexican Recipes"
# puts mex_cuisine.title # Mexican Recipes
# burrito.title = "Veggie Burrito"
# burrito.ingredients = ["tortilla", "tomatoes"]
# burrito.steps = ["heat tomatoes", "place tomatoes in tortilla", "roll up"]
# p burrito.title # "Veggie Burrito"
# p burrito.ingredients # ["tortilla", "tomatoes"]
# p burrito.steps # ["heat tomatoes", "place tomatoes in tortilla", "roll up"]
# mex_cuisine.recipes # []
# mex_cuisine.add_recipe(burrito)
# p mex_cuisine.recipes
# mex_cuisine.recipe_titles # Veggie Burrito
# mex_cuisine.recipe_ingredients # These are the ingredients for Veggie Burrito: ["tortilla", "bean"]
# burrito.print_recipe
# taco = Recipe.new("Crunchy Taco", ["shell", "lettuce", "cheese"], ["warm shell", "place lettuce", "add cheese"])
# mex_cuisine.add_recipe(taco)
# p mex_cuisine.recipes
# mex_cuisine.print_cookbook