Skip to content

Instantly share code, notes, and snippets.

@zegomesjf
Created August 22, 2012 12:37
Show Gist options
  • Save zegomesjf/3425179 to your computer and use it in GitHub Desktop.
Save zegomesjf/3425179 to your computer and use it in GitHub Desktop.
Object#presence

object.presence is equivalent to object.present? ? object : nil

Use

region = params[:state].presence || params[:country].presence || 'US'

instead

state   = params[:state]   if params[:state].present?
country = params[:country] if params[:country].present?
region  = state || country || 'US'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment