Method: String#words_without_punctuation
- Defined in:
- lib/core/facets/string/words.rb
#words_without_punctuation ⇒ Object
Returns an array of words in the commonly-understood sense (not including punctuation). This takes into account international punctuation characters as well as English ones.
'Slowly, grudgingly he said: "This has to stop."'.words
=> ["Slowly", "grudgingly", "he", "said", "This", "has", "to", "stop"]
16 17 18 19 20 21 22 |
# File 'lib/core/facets/string/words.rb', line 16 def words_without_punctuation s = self.dup s.gsub!(/[.?¿¡…!,::;—"。?!、‘“”„«»〈〉《》,\/\[\]]/, ' ') s.gsub!('- ', ' ') s.squeeze!(" ") s.strip.split(" ") end |