From: Logan Capaldo Date: 2006-04-13T10:18:36+09:00 Subject: Re: map_if, collect_if ??? --Apple-Mail-10--919812702 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Apr 12, 2006, at 9:04 PM, Mark Van Holstyn wrote: > Try using the 'select' method... > > irb(main):002:0* a = [ 1,2,3,4,5 ] > irb(main):003:0> b = a.select { |i| > irb(main):004:1* (i % 2 != 0) and (i * 10) > irb(main):005:1> } > => [1, 3, 5] > > Not the effect he was looking for: b = a.map_if { |i| (i % 2 != 0) and (i * 10) } p b [10, 30, 50] Personally I think his solution is a little icky, what if you wanted to do if x then map false a.map_if { |i| (i % 2 != 0) and false } would break down and you'd get an empty array I would just do a.select { |i| (i % 2 != 0) }.map { |i| i * 10 } if I needed map-if style functionality --Apple-Mail-10--919812702--