2017-08-23 6 views
-2

ルビーでレストラン管理コードを作成しようとしていました。しかし、getOrderメソッドでエラーが表示されていました。エラーメッセージがコンソールに示された ルビーで未定義のメソッドとFalseクラスエラー

マイコードがない&

if @amount <= $remainingAmmount && @amount > 0 
使用 &&
#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 

答えて

1

下に与えられる

"main.rb:26:in `getOrder': undefined method `>' for false:FalseClass (NoMethodError)                        
    from main.rb:45:in `<main>' " 

以下に示します。

関連する問題