In the Rails docs, the example provided for the object.presence
method is:
region = params[:state].presence || params[:country].presence || \'US\'
<
presence
is very useful when you want to return nil
if object is not present and the object itself if the object is present. In other words you want a code that looks like this:
object.present? object : nil
Instead of the line above you can simply call object.presence
and the method will do the work for you.