-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookbook.rb
83 lines (60 loc) · 2.19 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
class Cookbook
attr_accessor :title, :recipes
def initialize(title)
@title = title
@recipes = []
end
def add_recipe(recipe)
@recipes << recipe
end
def recipe_titles
@recipes.each do |recipe|
p recipe.title
end
end
def print_cookbook
@recipes.each do |recipe|
p "This is the recipe for: #{recipe.title}"
p "***********************"
p "These are ingredients:"
recipe.ingredients.each_with_index {|ingredient, index| p "#{index+1}. #{ingredient}"}
p "***********************"
p "And here is how you can do it:"
recipe.steps.each_with_index {|step, index| p "#{index+1}. #{step}"}
end
end
end
class Recipe
attr_accessor :title, :ingredients, :steps
def initialize(title, ingredients, steps)
@title = title
@ingredients = ingredients
@steps = steps
end
def print_recipe
p "This is a recipe FOR #{@title}"
p "This is what we need: #{@ingredients.join(',')}"
p "This is how we do it: #{@steps.join(',')}"
end
end
mex_cuisine = Cookbook.new("Mexican Cooking")
burrito = Recipe.new("Bean Burrito", ["tortilla", "bean"], ["heat beans", "place beans in tortilla", "roll up"])
mex_cuisine.title # Mexican Cooking
burrito.title # Bean Burrito
burrito.ingredients # ["tortilla", "bean", "cheese"]
burrito.steps # ["heat beans", "heat tortilla", "place beans in tortilla", "sprinkle cheese on top", "roll up"]
mex_cuisine.title = "Mexican Recipes"
mex_cuisine.title # Mexican Recipes
burrito.title = "Veggie Burrito"
burrito.ingredients = ["tortilla", "tomatoes"]
burrito.steps = ["heat tomatoes", "place tomatoes in tortilla", "roll up"]
burrito.title # "Veggie Burrito" burrito.ingredients # ["tortilla", "tomatoes"]
mex_cuisine.recipes # []
mex_cuisine.add_recipe(burrito)
mex_cuisine.recipes # [#<Recipe:0x007fbc3b92e560 @title="Veggie Burrito", @ingredients=["tortilla", "tomatoes"], @steps=["heat tomatoes", "place tomatoes in tortilla", "roll up"]>]
mex_cuisine.recipe_titles # Veggie Burrito
bunbohue = Recipe.new("Bun bo hue", ["hen", "bac ha"], ["cat rau", "xao hen","bo vo to"])
mex_cuisine.add_recipe(bunbohue)
#bunbohue.print_recipe
mex_cuisine.recipe_titles
mex_cuisine.print_cookbook