2011-12-23 74 views
1

我有多个模型方法,我想通过它们中的每一个进行循环和执行。我如何在rails 2.3.11中执行此操作?最好在开始/营救。rails - 在开始/救援中执行多个模型方法

编辑:

感谢maprihoda,我用你的榜样,并能够与开始/救援应用它:

class MyModel 
    def method_1 
    puts 'In method_1' 
    end 

    def method_2 
    puts 'In method_2' 
    end 

    def method_3 
    %w(method_1 method_2).each { |m| 
     begin 
     self.send(m) 
     rescue => e 
     puts "#{e.message}" 
     end 
    } 
    end 
end 
+0

很酷,问题upvoted – maprihoda 2011-12-24 11:05:34

回答

1

像这样的事情?

class MyModel 
    def method_1 
    puts 'In method_1' 
    end 

    def method_2 
    puts 'In method_2' 
    end 

    def method_3 
    %w(method_1 method_2).each { |m| self.send(m) } 
    end 
end 

my_model = MyModel.new 
my_model.method_3