I want to create an object, say, a pie.
class Pie
def initialize(name, flavor)
@name = name
@flavor = flavor
end
end
But the pie can be divided into 8 parts, half or just a whole pie. For argumentation, I would like to know how I can give each Pie object a price for 1/8, 1/4 or the whole. I could do this by doing:
class Pie
def initialize(name, flavor, price_all, price_half, price_piece)
@name = name
@flavor = flavor
@price_all = price_all
@price_half = price_half
@price_piece = price_piece
end
end
But now, if I created fifteen Pie objects, and I accidentally pulled out some fragments using a method such as
getPieceOfPie(pie_name)
How can I get the value of all available pies, which are whole and leftover parts? In the end, using a method like:
myCurrentInventoryHas(pie_name)
I know I'm new to Ruby. Thanks for your answers, comments and help!
Shyam source
share