我有一个 erb 模板,它为 httpd.conf 生成配置文件。
重要的是,最后写入特定位置(它是包罗万象的)
目前代码看起来像
cluster.apps.each do |app|
# Render config
end
我想重载应用程序对象上的每个方法以保证顺序。开始寻找如何执行此操作的最佳位置是什么?
如果你想超载它,你可以这样做
class Cluster
#..code
def each_application
return unless block_given? #ensure a block was given
a = @apps.shift #Implement this to grab the element you want
@apps.each{|x| yield x}
yield a #yield the element that you want last
end
end
所以你现在可以这样做:
cluster.each_application do |app|
#Render config
end
对于上面的当前实现,它将产生一行中的所有元素(除了第一个元素)。最后产生的项目是第一个被移走的项目。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)