Can't remember which book I saw it in (possibly Metaprogramming Ruby)
but at the beginning there is a statement along the lines of:

Think of an array. Now think of accessing that array. If your first
thought is a for loop then you need to read more about Ruby, if your
first thought is .each then you are ready to begin the concepts in
this book....... (something like that)

FWIW

Paul

On Aug 6, 12:22 am, Angel Robert Marquez <angel.marq...@gmail.com>
wrote:
> The design patterns book on Ruby I'm checking out says this:
>
> *Ruby also has a for loop, which you can use, among other things, to
> sequence*
> *through arrays:*
> *    array = ['first', 'second', 'third']*
> *    array.each do |x|*
> *      puts(x)*
> *    end*
> *
> *
> *Surprisingly, for loops are rare in real Ruby programs. A Ruby programmer
> is*
> *much more likely to write this equivalent code instead:*
> *    array.each do |x|*
> *      puts(x)*
> *    end*
> *
> *
> *We will have much more to say about this odd-looking loop thing in Chapter
> 7.*
> *For now, just think of the each syntax as another way to write a for loop.*
>
> On Thu, Aug 5, 2010 at 4:07 PM, David Kahn <d...@structuralartistry.com>wrote:
>
>
>
> > +1 for each (second). To me, the for reminds me of other languages where
> > you have to tell it what type of item the collection you are iterating
> > contains (I am thinking of C#), but in Ruby is not really an issue. I would
> > be interested in other opinions but to me not using 'for' just seems 'right'
> > and an easier read, maybe b/c this is what I seem to see most often.
>
> > On Wed, Aug 4, 2010 at 9:26 AM, Pale Horse <li...@ruby-forum.com> wrote:
>
> >> When looping through arrays. What'd you argue to be good (or best)
> >> practice?
>
> >> <% for something in @lots_of_things %>
> >>  <%= something.name %>
> >> <% end %>
>
> >> <% @lots_of_things.each do |something| %>
> >>  <%= something.name %>
> >> <% end %>
>
> >> I've read mixed opinions on this small topic. Some say that FOR loops
> >> are easier, though I cannot see how. Others say that EACH is a more
> >> 'railsy' method...
>
> >> Personally, I tend to use EACH as I was taught this to be correct and
> >> follow this rule to retain consistency in MY code. What is your opinion
> >> on this?
> >> --
> >> Posted viahttp://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 rubyonrails-t...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> rubyonrails-talk+unsubscr...@googlegroups.com<rubyonrails-talk%2bunsubscrib...@googlegroups.com>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/rubyonrails-talk?hl=en.
>
> >  --
> > 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-t...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > rubyonrails-talk+unsubscr...@googlegroups.com<rubyonrails-talk%2bunsubscrib...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/rubyonrails-talk?hl=en.- Hide quoted text -
>
> - Show quoted text -

-- 
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-t...@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.

Reply via email to