Ok guys, I am learning ruby and I am having a little bit of trouble with the tutorial. I was wondering if you could help me out!
Take the following code:
class Dish
def initialize(name, ingred, descrip)
@name = name
@ingred = ingred
@descrip = descrip
end
def name
@name
end
def name=(new_name)
@name = new_name
end
def ingred
@ingred
end
def ingred=(new_ingred)
@ingred = new_ingred
end
def descrip
@descrip
end
def descrip=(new_descrip)
@descrip = new_descrip
end
def display
puts "I am a #{@name} and my ingredient is #{@ingred} and my description is #{descrip}"
end
end
dis1 = Dish.new('Pizza', 'sauce', 'put sauce on that thing')
dis1.display
Ok so here is my question and I hope I explain it well enough. So far I have learned to take enter one parameter when making a new instance of a class (i.e. (name, ingred, descrip)). What I am wondering is if a dish has multiple ingredients, how would I add that to my class? Also, if I wanted to count the number of ingredients or the number of names, how would I do that. I am just learning about classes and I am having trouble matching the exact wording I would Google for. Thanks!
@ingredients.size. You could easily add or remove ingredients as well.