以下の内容はhttps://blog.willnet.in/entry/20110525/1306346843より取得しました。


Object#presence

rails が追加しているメソッド。真ならオブジェクト自身を返して、偽なら nil を返す。

object.present? ? object : nil.

と同じ。下記のような、パラメータをチェックして使うよくある感じのコードが

state   = params[:state]   if params[:state].present?
country = params[:country] if params[:country].present?
region  = state || country || 'US'

こんな風に一行にまとまる。便利かも?

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

Rails 3, またはRails 2.3.8 くらいから使えます。




以上の内容はhttps://blog.willnet.in/entry/20110525/1306346843より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14