2017-01-17 19 views
0

我以前從未使用過Ruby,並且試圖在2006年編寫程序。我已經安裝了Ruby和gem包,但是當我嘗試運行它,我得到一個錯誤:Ruby - 「正式參數不能是類變量」

xmltv2html.rb:231: formal argument cannot be a class variable 

xmltv2html.rb:231: syntax error, unexpected '[', expecting '|' 

面積給我的麻煩,特別是

 def parse_command_line_options 
    ARGV.options do 
     |opts| 
     opts.banner = "Usage: #{File.basename($0)} <xmltv.xml> tv.html\n" 


     # separater 
     opts.on_tail 
     opts.on_tail("common options:") 

     opts.on("--configfile=FILE", String, "config file to use") { 
      |@@options[:config_file]|} 

     #more code after 

我試圖使用該項目是「xmltv2html」。

有什麼特別的我做錯了嗎?我嘗試將'| @@選項'更改爲'| @options'和'| $ options',但只是更改錯誤消息以反映相關範圍。

這只是一個使用太舊項目的案例嗎?

預先感謝塊參數

+0

的可能的複製(http://stackoverflow.com/questions/23092993/ rails-formal-argument-can-be-an-instance-variable) –

+1

在'| @@ options [:config_file] |'上檢查你的代碼 - 這是塊的無效參數 –

+0

@ Slava.K對於新手?記住這不是我的代碼,我從來沒有使用Ruby,我試圖讓我的頭腦圍繞這一切! – twgh

回答

4

分配語義紅寶石1.9.0中除去(在2007年發佈)。你將不得不重組的代碼來執行自己的任務,像這樣:[?Rails的正式參數不能是一個實例變量]

opts.on("--configfile=FILE", String, "config file to use") do |config_file| 
    @@options[:config_file] = config_file 
end 
+0

非常感謝,先生。您的建議在解決錯誤和提高我的知識方面表現良好。 – twgh