From: Benoit Daloze Date: 2009-11-13T23:12:16+09:00 Subject: Re: Enumerable#find_yield, useful shortcut? better name? --0016e6482b5c0340d80478413fd8 Content-Type: text/plain; charset=ISO-8859-1 As Aaron, I prefer the simple built-in method, with what u want to do with the object after: obj1.foo? #=> false obj2.foo? #=> true obj2.foo #=> "value" [obj1, obj2].find_yield { |obj| obj.foo if obj.foo? } #=> "value" [obj1, obj2].find { |obj| obj.foo? }.foo #=> "value" Even more concise ... The only problem I see is if we don't find, we'll call foo on nothing(nil). So to have the same behavior: x = [obj1, obj2].find(nil) { |obj| obj.foo? } x.foo unless foo.nil? #=> "value" And I think it's quite normal we have to manage with a structure(the if) how to manage when we didn't find. But I'm probably missing a special case. Could you give a example in situation, to see if it is easier to read or not? If you want to take several objects, you would use [obj1, obj2].select { |obj| obj.foo? }.map {|e| e.foo} So the idea of Robert Klemme is accurate, sure. 2009/11/13 Martin DeMello > On Thu, Nov 12, 2009 at 9:37 PM, Intransition wrote: > > This method has long been suggested to me as #map_detect. At first I > > wasn't sure of it's usefulness. But now I think it's okay. (Your > > thoughts?). In any case, the name has to go. Currently I'm thinking > > #find_yield. Any better suggestions? > > #where doesn't read too badly > > martin > > --0016e6482b5c0340d80478413fd8--