configatron을 사용하여 구성 값을 저장하고 있습니다. 범위 값이 클래스의 메서드 내에있는 경우를 제외하고는 문제없이 config 값에 액세스 할 수 있습니다. 루비 여기에 2.0.0구성 단일체? 내 수업에서 configatron에 액세스 할 수없는 이유는 무엇입니까?
와
내가 configatron 사용하고 3.0.0-RC1 내가 '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
I라는 하나의 파일에 사용하고 소스입니다 코드를 실행, 나는 사이
{: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 싱글을받지 못했습니다 이유를 모르겠어요 출력 '을 간단하게 마무리'.
무엇이 누락 되었습니까? Kernel
마다 객체에 사용 가능한 방법하게 Object
에 포함되므로
내가 말할 수있는 것은 고맙다. 놀랍다. – John