From: Michael Michael Date: 2009-01-15T01:17:45+09:00 Subject: Re: a beginner case question I don't mean to be too intrusive as I am a dreadful IT Recruiter that you probably all despise. I am working on filling a number of RoR Developer positions(beginners are welcomed) for an exciting young company in NYC. If you are interested in learning more about the position please e-mail me, mmartino@apexsystemsinc.com or call me at 212.991.1835. No one has to know that you contacted me regarding and you can still bash me here in the blog. Have a great day! Thanks! Taylor Strait wrote: > I am using case in to determine the sorting method used for an array as > so: > > def single_choice(object) > > # sort answer order based on question.list_method > answers = object.answers > > sorted_answers = case object.list_method > when 'position' then answers.sort_by {|answer| answer.position} > when 'random' then answers.sort_by {rand} > when 'alphabetical' then answers.sort_by {|answer| answer.text} > when 'reverse_alpha' then answers.sort_by {|answer| answer.text} > return answers.reverse > when 'shortest_first' then answers.sort_by {|answer| > answer.text.length} > when 'longest_first' then answers.sort_by {|answer| > answer.text.length} > return answers.reverse > end > > This does not because of the return statements. However, I need to > reverse the result for those two options. How can I do this with case > statements? Or must I use if..elsif? -- Posted via http://www.ruby-forum.com/.