【发布时间】:2013-11-10 21:27:23
【问题描述】:
我有如下代码(为了便于阅读,已截断/转述)
def board_check?
@board.each {|row| check_row_for_truth_conditions(row)}
end
def check_row_for_truth_conditions(row)
return true if row.include("foo")
false
end
现在每个迭代器的隐式返回总是它正在迭代的集合。 IE;我得到了数组,不是真假。如果我不重构并执行以下操作,它将按预期工作。但是我在很多地方都使用了 check_row_for_truth_conditions(而且它更长),所以想重构它
def board_check?
@board.each do |row|
return true if row.include("foo")
false
end
end
【问题讨论】:
-
我想通了。我可以通过使用任何东西得到我想要的东西吗?而不是每个。所以
@board.any? {|row| check_row_for_truth_conditions(row)}
标签: ruby each enumerable