From: Taylor Strait Date: 2009-01-15T07:50:57+09:00 Subject: Re: a beginner case question F. Senault wrote: > To go a step further than just answering your question, I'd refactor the > whole function like this : > > def single_choice(object) > l = case object.list_method > when /^position/ then lambda { |x| x.position } > when /^rand/ then lambda { rand } > when /^alpha/ then lambda { |x| x.to_s } > when /^length/ then lambda { |x| x.length } > end > sorted_answers = object.answers.sort_by(&l) > if order =~ /desc$/ > sorted_answers.reverse! > end > sorted_answers > end That is great usage of regex's -- thanks for showing me that! -- Posted via http://www.ruby-forum.com/.