Wednesday, October 27, 2010

Re: [Rails] Empty array check

On 27 October 2010 11:43, Pale Horse <lists@ruby-forum.com> wrote:
> Which of the two methods below are the most stable? Does it matter?
>
> !@articles.empty?
> @articles.length > 0
>
> I personally prefer using the 'empty?' method.

Between the two, I'd use ".empty?", but at a choice I'd use neither,
and go for ".blank?" instead.
".blank?" can be a bit more "stable" as it returns true for nil
values, as well as blank strings, empty arrays and hashes...

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate