2016-04-06 40 views
-3

error:C:\Users\RR\Desktop\ruby_sandbox>ruby classes.rb classes.rb:44: syntax error, unexpected end-of-input, expecting keyword_end我無法執行該程序

我的代碼是:

class Animal 

attr_accessor :name,:age,:sex,:location 


def initialize(age=18,sex="not available",location="not specified") 

    puts "details of animal" 

    @age=age 
    @sex=sex 
    @location=location 
end 

def condition(age,name) 
    if animal.age>animal1.age 
    puts "#{animal.name } is older than #{animal1.name}" 
    else 
    puts "animals age are in increasing order" 
    end 
end 
+1

你應該在末尾加上'end' – Ilya

+0

謝謝你的幫助..我檢查一下.. – pHorekka

+0

同樣值得注意的是'animal1'是你指的東西,但從來沒有被定義在任何地方。 – tadman

回答

1

請照顧好你的縮進,而編寫Ruby,你會看到你錯過了end關鍵字。

但在你的情況下,問題不僅在於開始修復之前的縮進問題。您可以查看一些關於Class and Instance Methods in Rubythis tutorial的文檔可以幫助您解決您的問題。

祝你好運。

+0

適當的縮進不能強調不夠。當你的代碼錯誤發生時,你會馬上就會發生,而且他們通常是非常愚蠢的,通過保持整潔可以避免。 – tadman

+0

你是對@tadman .....並且感謝thatway_3對於那些教程的建議...... – pHorekka