Permalink
Browse files

Generalise 1..n word loop

  • Loading branch information...
kerryb committed Jul 15, 2009
1 parent e10845f commit 8be9301f293231611e4bc6a8b4455e74189aab2c
Showing with 3 additions and 2 deletions.
  1. +3 −2 1.rb
View
5 1.rb
@@ -8,8 +8,9 @@ module StringExtensions
def phrases(number)
words = split
all_strings = words
- all_strings += extract_phrases(words, 2)
- all_strings += extract_phrases(words, 3)
+ (2..words.size).each do |number_of_words|
+ all_strings += extract_phrases(words, number_of_words)
+ end
all_strings[0, number].map {|s| "'#{s}'"}.join(', ')
end

0 comments on commit 8be9301

Please sign in to comment.