If the only word boundary is one space, just count them.
puts "this sentence has five words".count(' ')+1
If there are spaces between words, line endings, tabs, comma, and then space, etc., then the ability to scan word boundaries is possible:
puts "this, is./tfour words".scan(/\b/).size/2
source share