Deleting items from an array requires multiple passes to remove them all

前端 未结 2 709
一个人的身影
一个人的身影 2021-02-13 12:35

I have an array of ~1200 ruby objects and I want to loop over them and delete the ones with names that contain words or parts of words.

So I tried this:

         


        
2条回答
  •  再見小時候
    2021-02-13 12:41

    There is another way to do the same as reject! with delete:

    list.delete_if { |item| item =~  /cat|dog|rat/i }
    

提交回复
热议问题