0

为了让我的应用程序只有一个配置点,我需要制作一个 YAML 配置文件,它也是有效的 ruby​​ 代码。即可以解析为 YAML 并解析为 ruby​​ 的混合语法文件。

我的应用程序是一组由godgem 管理的进程。我想为每个新的配置文件加载一组新的维护进程(监视)。

上帝允许加载定义了新手表的新 app.god (ruby) 文件,但我不想要 app.god 和 app.yml,只有一个文件。最简单的可能是只拥有 app.god 文件并在其中包含配置,但我更喜欢 yml 文件的想法,它也是有效的 ruby​​ 代码。

4

1 回答 1

0
#I found this that might be helpful:
#This is a valid ruby and a valid YAML file
#Comments are the same in YAML and ruby

true ?true: 
- <<YAML.to_i
# At this point in ruby it is the contents of a here doc (that will be 
# converted to an integer and negated if true happens not to be true)
# In YAML it is a hash with the first entry having key "true ?true"
# representing a list containing the string "- <<YAML.to_i"
# If your YAML object should be a list not a hash you could remove the first line

any_valid_yaml:  from here
a_list:
- or
- anything
- really
#Then mark the end of the YAML document with 
---
#And YAML is done and ignores anything from here on
#Next terminate the ruby here document
YAML

#Now we're in ruby world

@this = "pure ruby"

def anything(ruby)
   "here"
end
于 2014-04-10T08:33:22.073 回答