module StringExtensions def words s = self.dup s.gsub!(/\w+/, 'X') s.gsub!(/\W+/, '') s.length end end
s.scan(/(\w|-)+/).size
BTW, Peter, I hadn't happened upon "scan" until reading your book. Thanks!
You need to create an account or log in to post comments to this site.