Ruby Flare

Your awesome Tagline

2 notes

Presence

I just came across this object method in Rails (when did this go in?):

Instead of writing something like:

state = params[:state] if params[:state].present?

you can now do:

state = params[:state].presence

Object.presence is the equivalent of object.present? ? object : nil

See the docs

Filed under rails

  1. rubyflare posted this