-2
我試圖在ruby上做一個餐廳管理代碼。但它顯示我在getOrder
方法錯誤。ruby中未定義的方法和False類錯誤
在控制檯中顯示錯誤消息下面
"main.rb:26:in `getOrder': undefined method `>' for false:FalseClass (NoMethodError)
from main.rb:45:in `<main>' "
給出我的代碼是下面給出
#creating a class
class Hotel
# creating a local haah variable with the name of the items and amount
detailedMenu ={"Pizza"=>100, "FriedChicken"=>70, "Burrito" => 50}
#creating class (array) variable to store item and amount seperately
@@menus= detailedMenu.keys
@@amount= detailedMenu.values
puts @@amount.at(1)
#initializatin method
def initialize(item,number)
@item=item
@amount= number
end
def getOrder()
#checking wheather the item is in item list or not
if @@menus.include?(@item)
[email protected]@menus.index(@item)
$remainingAmmount= @@amount.at(a)
#checking wheather the required amount of the item is available or not
if @amount<= $remainingAmmount & @amount> 0
puts " Your order has been placed successfuly "
$remainingAmmount [email protected]
#@@amount.at(a)= $remainingAmmount
elsif @amount<=0
puts "Please enter a valid amount"
else
puts "Sorry, we don't have that much #@item . You can try for a little less amount"
end
else
puts "We don't serve this item. Please choose from #@@menus"
end
end
end
#creating new object
order1 = Hotel.new("Pizza" , 50)
#calling the method
order1.getOrder