I want to split a string by whitespaces, , and \' using a single ruby command.
word.split will split by white spaces
You can use a combination of the split method and the Regexp.union method like so:
delimiters = [',', ' ', "'"]
word.split(Regexp.union(delimiters))
# => ["Now", "is", "the", "time", "for", "all", "good", "people"]
You can even use regex patters in the delimiters.
delimiters = [',', /\s/, "'"]
word.split(Regexp.union(delimiters))
# => ["Now", "is", "the", "time", "for", "all", "good", "people"]
This solution has the advantage of allowing totally dynamic delimiters or any length.