From: Gavin Sinclair [mailto:gsinclair / gmail.com] # On Aug 3, 5:58 pm, Peñá, Botp <b... / delmonte-phil.com> wrote: # > min = list.sort!{|a,b| a.size <=> b.size}.first # > break if list.all?{|a| a =~ /^#{min}/} while min.chop! # I just realised that the solution I just posted elsewhere in this # thread is very very similar to this one. # Be careful that using bang methods in chains is sometimes problematic, # as they can return nil if nothing changes (sort! doesn't have this # problem). indeed. as long as the array has no nil elements, w're ok w sort! irb(main):009:0> s="test" => "test" irb(main):010:0> s.downcase!.downcase! NoMethodError: undefined method `downcase!' for nil:NilClass from (irb):10 from :0 irb(main):011:0> a=[1,1,1] => [1, 1, 1] irb(main):012:0> a.sort!.sort! => [1, 1, 1] i realized just now that i posted the first code. That should be, min = list.sort!{|a,b| a.size <=> b.size}.shift # <--shift instead of first break if list.all?{|a| a =~ /^#{min}/} while min.chop! but anyway, after a couple of tests, the sort does not help much, so min = list.min{|a,b| a.size <=> b.size} break if list.all?{|a| a =~ /^#{min}/} while min.chop! hmm.. Gavin, your until code just gave me a hint. if we reverse logic, we can save the break and make it more readable too. min = list.min{|a,b| a.size <=> b.size} min.chop! until list.all?{|a| a =~ /^#{min}/} and we can use switch w #any? anytime too :) min = list.min{|a,b| a.size <=> b.size} min.chop! while list.any?{|a| a !~ /^#{min}/} ruby power, indeed. kind regards -botp