In the Rails docs, the example provided for the object.presence method is:
object.presence
region = params[:state].presence || params[:country].presence || \'US\' <
I just used it in a useful way I found neat. My variable is a string, if it's the empty string i want nil, otherwise I want it converted to an integer.
x.presence.try(&:to_i) "".presence.try(&:to_i) # => nil "22".presence.try(&:to_i) # => 22