Calculate From Subclass

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

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
end
end

#second class Restaurant
class Restaurant < Menu
def countorder
# some code
#puts how many ordered so far
end
def earned
# some code
#puts how much was the order so far
end
end
object = Restaurant.new( :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 = Restaurant.new(:Salad, :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 = Restaurant.new

order = Menu.new(“Pizza”, “Ham”, 15.0)
order.print
restaurant.add_order(order)

order = Menu.new(“Salad”, “Beef”, 7.50)
order.print
restaurant.add_order(order)

puts “The restaurant has #{restaurant.order_count} orders and earned
$#{restaurant.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.