ruby 以hash方式读取.rb文件
Chef中的attribute file都是XXX.rb格式,有什么方法可以把这种XXX.rb格式的文件转换成.json格式的文件吗?
或者
像JSON.parse()方法一样,把.rb文件读取成一种obj类型的hash。
如:
$test['apache']['httpd.conf'] = {
'ServerTokens' => "ProductOnly",
'deflate' => {
'DeflateCompressionLevel' => '1'
},
'KeepAlive' => "On",
'KeepAliveTimeout' => "5",
'ListenBackLog' => "511"
}
其中$test['apache']['httpd.conf']是key,
而{
'ServerTokens' => "ProductOnly",
'deflate' => {
'DeflateCompressionLevel' => '1'
},
'KeepAlive' => "On",
'KeepAliveTimeout' => "5",
'ListenBackLog' => "511"
}是value,依次递归这样读取。
请问有实现的方法吗?