Calculate From Subclass

I have two classes one has a menu and the other processes some

class Menu
initialize variables(type, meat, price)

#create attr_accessors of each
attr_accessor :type
attr_accessor :meat
attr_accessor :price

def order
puts type, meat and price

#second class Restaurant
class Restaurant < Menu
def countorder
# some code
#puts how many ordered so far
def earned
# some code
#puts how much was the order so far
object = :Pizza, :Ham, 15.0 )
firstorder = object.order #will puts type, meat and price of order
puts object #should puts order # and the total ordered

object2 =, :Beef, 7.50)
firstorder = object2.order #will puts type, meat and price of order
puts object2 #shoudl then show order #2 and total of 15 + 7.50

I’m having some scope issues I’m not sure how to calculate and track the
count of order on the subclass and do total = total + @price.

Jesus Castello wrote in post #1172026:

I don’t think Inheritance is the right choice here, Restaurant is not a
specialization of a Menu, but rather Restaurant uses Menu as part of
its operations. Here is my working solution using composition.

restaurant =

order =“Pizza”, “Ham”, 15.0)

order =“Salad”, “Beef”, 7.50)

puts “The restaurant has #{restaurant.order_count} orders and earned

I see that looks great. My thinking is that a menu is part of a
restaurant that’s why I had the inheritance. Thanks again.