2011-12-23 28 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