How can i remove a repeating string keyword from all elements in an array ?
2 Answers
I think you mean you have an array of strings and they all contain some substring that you want to remove. Non-destructively:
array.map {|s| s.gsub(keyword, '')}
Use destructive variants as desired to do it in-place.
3 Comments
glenn jackman
here's a destructive (in-place) example:
array.each {|word| word.delete!('aeiou')}glenn mcdonald
here's another destructive (in-place) example:
array.map! {|word| word.gsub(keyword,'')}glenn mcdonald
we are the destructoglenns