在Settingslogic fork允許數組作爲源,在紅寶石1.8.7一切正常,但在紅寶石1.9.2有一個錯誤。問題是這部分代碼中:Ruby 1.9.2 class_eval變量
self.class.class_eval <<-EndEval
def #{key}
return @#{key} if @#{key}
raise MissingSetting, "Missing setting '#{key}' in #{@section}" unless has_key? '#{key}'
value = fetch('#{key}')
@#{key} = value.is_a?(Hash) ? self.class.new(value, "'#{key}' section in #{@section}") : value
end
EndEval
@section == ["path_to_yml_file1", "path_to_yml_file2",...]
貌似#{}在一些奇怪的方式進行評估,「#{@}節」似乎是一個數組,而不是一個字符串。有人可以解釋這一點嗎?
錯誤跟蹤:
@section == ["User/project/config/defaults.yml", "/Users/project/config/development.yml"]
ruby-1.9.2-p290 :001 > Settings.keys
SyntaxError: (eval):3: syntax error, unexpected tSTRING_BEG, expecting keyword_end
...project/config/defaults.yml", "/Users/project...
... ^
(eval):3: syntax error, unexpected tSTRING_BEG, expecting keyword_end
...project/config/development.yml"]" unless has_key? 'front'
... ^
(eval):5: syntax error, unexpected tSTRING_BEG, expecting ')'
...project/config/defaults.yml", "/Users/project...
... ^
(eval):5: syntax error, unexpected tSTRING_BEG, expecting keyword_end
...project/config/development.yml"]") : value
... ^
(eval):5: syntax error, unexpected ')', expecting keyword_end
...project/config/development.yml"]") : value
... ^
from .../settingslogic-3b5d7d9cc319/lib/settingslogic.rb:198:in `class_eval'
感謝所有幫助
什麼是@section == [「User/project/config/defaults.yml」,「/Users/project/config/development.yml」]? –
只是一個快捷方式,目的是顯示@section的值是多少... – santuxus