我正在使用 Ruby on Rails 3.2.2,我想知道是否可以在“运行”/“加载”时检索到的每条记录上运行一个方法,以便仅“保留”/“返回”那些记录该方法返回,直到那些是 5。也就是说,我有:ActiveRecord::Relation
true
class Comment < ActiveRecord::Base
def method_name
# return 'true' or 'false'
end
end
# The '<...>' in the below code could / should be stated to run the 'method_name'
# on each comment and keep those comments for which 'method_name' returns 'true'
# until the count of retrieved comments is 5.
Comment.where(:published => true).<...>
Comment.<...>