On May 27, 9:35 am, Vipin <sh.vi...@gmail.com> wrote:
> Looking for suggestions on following two queries.
>
> Query 1
> ------------------------------
> Are the two following lines of code different in Ruby / Rails ( in a
> *.html.erb) file.
> <% if @forms.count != 0 %> <!-- first code -->
> Vs.
> <% if @forms.count %> <!--second code -->
>
> @forms is an array of objects. Coming from "C" language development
> background, i thought they should be the same. FYI, second code
> doesn't give any error but still gets evaluated to TRUE. I confirmed
> by doing puts @forms.count in controller
They are different. in ruby, 0 has the logical value true (only nil
and false have the logical value false)
>
> Query 2
> ------------------------
> which one is preferred
> @forms. count or @forms.size
> @forms is an array.
>
if forms is actually an array, forms.count doesn't exist (but it does
if it is an association proxy, eg person.friends).
Fred
> thanks
> vipin
--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---