2012-01-07 41 views
1

我用屈,並有一個問題,我解決不了,這裏是代碼:Ruby方法範圍如何工作?

require 'sinatra' 

def url(s) 
    get s do yield end 
    post s do yield end 
end 

url '/' do 
    erb :index 
end 

然後,程序提示,:未定義的方法`再培訓局」主:對象

我該怎麼辦?

回答

1

你可以嘗試這樣的事:

require 'rubygems' 
require 'sinatra' 

def map_url(url, options={}, &block) 
    get(url, options, &block) 
    post(url, options, &block) 
end 

map_url '/' do 
    erb :index 
end 
+0

甚至:'def map_url(* args,&block); get(* args,&block); post(* args,&block); end'。這應該抓住一切。 – 2012-01-07 20:13:51