In Ruby & in RoR I oft find myself testing whether an object exists, then whether an object’s properties match some criteria. Like so:
if params[:id] && params[:id].size == 40
...do stuff
end
Is there a more efficient way to do this? Something like:
if params[:id].size == 40 rescue false
but without using the rescue?
With Rails 2.3 you can use Object#try method:
try will return nil when called on nil (with any arguments). Hope that makes sense.