<分区>
Possible Duplicate:
check if value exists in array in Ruby
我有一个循环遍历字符串数组并在任何字符串包含字符串“狗”时返回 true 的方法。它正在工作,但多个 return 语句看起来很乱。有没有更 Eloquent 方式来做到这一点?
def has_dog?(acct)
[acct.title, acct.description, acct.tag].each do |text|
return true if text.include?("dog")
end
return false
end