Enumerable#collect and #select best practices

I need to collect the results of calling a method on each object in an
Enumerable that defines that method. Currently, I have this:

enum.collect{|obj| obj.a_method rescue nil }.compact

though this could also work:

enum.select do |obj|
obj.respond_to? :a_method
end.collect{|obj| obj.a_method }

although that’s a bit verbose.

Is there any best practices I should follow?

Daniel

Daniel S. wrote:

enum.collect{|obj| obj.a_method rescue nil }.compact

@#%&@½£@!!!

The simple version didn’t work (only in my head), so I’m back at the
verbose version…

Daniel