Alpha Blue wrote:
> Thanks fellas.  I took the latter tip to heart and removed the quotes 
> and used .to_s
> 
> As for the [i], I'm iterating over multiple queries that have the exact 
> same row count.  Therefore, I don't need to use each.  I do use each and 
> each_with_index a lot.
> 
> (1..120).each do |i|
> ...
> end
> 
> .. this suffices and allows me to count the exact number of iterations I 
> need.  

NO! NO! NO!

You've hard-coded the value 120.  There's absolutely NO reason to do 
that, and it just makes your code more brittle.  Worse, you're using a 
"magic number" to do it, not a symbolic constant, so it will be harder 
to change each instance when the next team joins the NCAA.  If you just 
did @rows.each, you'd never need to change it.

Why introduce pointless couplings and dependencies into your code?  The 
array already knows how many records it contains, so let it keep track 
itself.

> In cases where I don't know the row count, or the row count isn't 
> the same count across multiple tables, I don't use the above.

You should only ever use that syntax if you're actually dealing with the 
numbers 1 to 120 as data (say, if you're calculating the first 120 
factorial numbers).  If you want to iterate over a recordset, *always* 
use each.
> 
> Thanks.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
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 [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-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to