We already have Object#present? :)

On Sun, Dec 27, 2009 at 7:49 AM, ColinDKelley <[email protected]> wrote:
> All,
>
> I'd like to propose the Object#nonblank? in ActiveSupport, layered
> over the blank? method.  This has been working well for us in the past
> year and hopefully others will find it useful enough to include in
> core.
>
> It is analogous to Ruby's Numeric#nonzero? method: it either returns
> the object itself (if not blank) or nil (if blank). This makes it easy
> to treat blank parameters the same as missing ones, and allows
> chaining:
>
> For example, this:
>
>  state   = params[:state]   unless params[:state].blank?
>  country = params[:country] unless params[:country].blank?
>  region  = state || country || 'US'
>
> becomes:
>
>  region = params[:state].nonblank? || params[:country].nonblank? ||
> 'US'
>
> The ticket is here:
>
> https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3620-objectnonblank-analogous-to-rubys-numericnonzero#ticket-3620-2
>
> along with a patch that includes full documentation and tests.
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Core" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-core?hl=en.
>
>
>



-- 
Cheers!
- Pratik
http://m.onkey.org | http://twitter.com/lifo

--

You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.


Reply via email to