From 8be9301f293231611e4bc6a8b4455e74189aab2c Mon Sep 17 00:00:00 2001 From: Kerry Buckley Date: Wed, 15 Jul 2009 08:57:15 +0100 Subject: [PATCH] Generalise 1..n word loop --- 1.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/1.rb b/1.rb index 92d9ed3..d17f942 100755 --- a/1.rb +++ b/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