按顺序重载每个方法

我有一个erb模板,它为httpd生成配置文件。

最后写一个特定的位置很重要(这是一个全部的记录)

目前代码看起来像

cluster.apps.each do |app| # Render config end 

我想重载apps对象上的每个方法以保证顺序。 什么是开始寻找如何做到这一点的最佳地点?

如果你想超载它,你可以做类似的事情

 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 

并且通过上面的当前实现,它将连续产生所有元素(第一个除外)。 最后一个产生的项目是第一个被移除的项目。