2
我正在使用configtron來存儲我的配置值。除非範圍在類的方法內,否則我可以毫無問題地訪問配置值。configtron單身?爲什麼我不能在我的課堂上訪問configtron
我使用configatron 3.0.0-RC1使用Ruby 2.0.0
下面是我用了所謂的 'tc_tron.rb'
require 'configatron'
class TcTron
def simple(url)
puts "-------entering simple-------"
p url
p configatron
p configatron.url
p configatron.database.server
puts "-------finishing simple-------"
end
end
# setup the configatron. I assume this is a singleton
configatron.url = "this is a url string"
configatron.database.server = "this is a database server name"
# this should print out all the stuff in the configatron
p configatron
p configatron.url
p configatron.database.server
# create the object and call the simple method.
a = TcTron.new
a.simple("called URL")
# this should print out all the stuff in the configatron
p configatron
p configatron.url
p configatron.database.server
當我一個文件源運行代碼,我得到
{:url=>"this is a url string", :database=>{:server=>"this is a database server name"}}
"this is a url string"
"this is a database server name"
-------entering simple-------
"called URL"
{}
{}
{}
-------finishing simple-------
{:url=>"this is a url string", :database=>{:server=>"this is a database server name"}}
"this is a url string"
"this is a database server name"
之間的「進入簡單」和「完成簡單的」輸出我不知道爲什麼我沒有得到configatron單。
我錯過了什麼?
我所能說的全部都是感謝和驚訝。 – John