是否有一个 Ruby 习语用于在条件为真时从数组中弹出项目并返回集合?
IE,
# Would pop all negative numbers from the end of 'array' and place them into 'result'.
result = array.pop {|i| i < 0}
据我所知,不存在上述情况。
我目前正在使用
result = []
while array.last < 0 do
result << array.pop
end