【发布时间】:2011-12-14 09:46:49
【问题描述】:
我正在开发一个 Ruby on Rails 应用程序。我的问题更多关于 Ruby 语法。
我有一个带有类方法self.check的模型类:
class Cars < ActiveRecord::Base
...
def self.check(name)
self.all.each do |car|
#if result is true, break out from the each block, and return the car how to...
result = SOME_CONDITION_MEET?(car) #not related with database
end
puts "outside the each block."
end
end
我想停止/突破each 块一旦result 为true(如果car.name 则打破each 块与name 参数once 相同)并返回导致true 结果的car。如何在 Ruby 代码中突围?
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.1