1
我記得之前出現過這個問題,但找不到答案。需求後的Ruby默認類操作
我需要一個文件是這樣的:
#lib/tm/agent/server.rb
require 'tm/agent/server'
,並在不顯式調用監聽類,它的initialize
得到執行:
module Tm
module Agent
module Server
require 'goliath'
class Listen < Goliath::API
def initialize
puts "WHAT"
end
def response(env)
[200, {}, "Hello World"]
end
end
end #end Server
end #end Agent
end #end Tm
如何避免初始化上要求類?
也許這可能有助於http://stackoverflow.com/questions/3745252/require-file-without-executing-code – halfelf