lets say i’ve got this array:
array = ["str1", "str2", "str3", "str4", "str5", "str6", "str7", "str8"]
what i’m doing:
array.delete_if {|i| i == "str1" || i == "str3" || i == "str5"}
i got:
["str2", "str4", "str6", "str7", "str8"]
are there any better approach in ruby to do this ?
You could do this:
Note that this returns a new array with
"str1","str2", and"str3"removed, rather than modifiyingarraydirectly (asdelete_ifdoes). You can reassign the new array toarrayconcisely like this: