From: Phrogz Date: 2007-12-12T11:35:02+09:00 Subject: Re: How To Avoid Ugly Declerations On Dec 11, 6:49 pm, Michael Boutros wrote: > Suraj Kurapati wrote: > > Michael Boutros wrote: > >> def some_method(foo) > >> results = [] > >> foo.each {|f| results << f.reverse} > >> return results > >> end > > >> As you can see, that is some pretty ugly code, but it's also a common > >> scenario. How can I make it a little less ugly? > > > def some_method foo > > foo.map {|f| f.reverse} > > end > > Thanks for that, I'll be using that more often now :) However, I'm > having trouble refactoring this code into something like yours... > > def get_text(*elements) > results = [] > elements.each {|element| results << self.search(element).first} > return results > end def get_text( *elements ) elements.map{ |el| search( element ).first } end