2012-04-30 148 views
1

我正在爲Ruby機架架構,運行App::Router模塊下面的內:在模塊內部包含外部Ruby模塊?

module App 
    Router = HttpRouter.new do 
     get('/') { |env| erb('home') } 
    end 
end 

通知的erb()方法我希望在我的路由器使用。問題是從外部源(我的框架)獲取方法到一個模塊中,並傳入內部的do塊。

是否有從外部源獲取模塊到另一個文件中的模塊的可能方法?

謝謝。

+0

檢查這個問題,它的答案了: http://stackoverflow.com/questions/7950463/calling-erb-without-rails-undefined-method-raw – TonsOfFun111

回答

1

是你定義的某個方法嗎?嘗試是這樣的:

require 'path/to/module/with/erb_method' 
    module App 
     include YourModule 
     Router = HttpRouter.new do 
     get('/') { |env| erb('home') } 
     end 
    end 
2
module App 
    def foo 
    "bar" 
    end 
end 

module Route 
    include App 
end 

include Route 

foo 
=> "bar"