我正在开发一个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
块once停止/中断result
是true(如果car.name
与name
参数once相同,则中断each
块),并返回导致true结果的car
.如何在Ruby代码中突破?