How to simplify split, iterate.each and join ruby? - Ruby newbie

words = self.tag.split
words.each { |word| word = word.stem }
self.tag = words.join(' ')

For this sentence, I want to perform an action stemfor each individual word .

Is there any way to simplify this code?

+5
source share
2 answers
self.tag = self.tag.split.map(&:stem).join(' ')
+12
source
self.tag = self.tag.split.collect { |w| word.stem }.join(' ')

Not that I definitely recommend this.

+1
source

All Articles