concept iteration in category ruby

appears as: iteration, iterations, iterations, n iteration, iteration
The Well-Grounded Rubyist, Third Edition

This is an excerpt from Manning's book The Well-Grounded Rubyist, Third Edition.

  • Iteration—A call to a method is supplemented with a segment of code that the method can call one or more times during its own execution.
  • >> 5.times {|i| puts "I'm on iteration #{i}!" }
    I'm on iteration 0!
    I'm on iteration 1!
    I'm on iteration 2!
    I'm on iteration 3!
    I'm on iteration 4!
    => 5

    The loop method has access to the code inside the block: the method can call (execute) the block. To do this from an iterator of your own, you use the keyword yield. Together, the code block (supplied by the calling code) and yield (invoked from within the method) are the chief ingredients of iteration.

    Flexible Rails: Flex 3 on Rails 2

    This is an excerpt from Manning's book Flexible Rails: Flex 3 on Rails 2.

    In this book, the chapters are called iterations. I’ve done this because we’ll develop an application iteratively throughout the book—it has nothing specific to do with Flex or Rails. (That said, both Flex and Rails lend themselves to an iterative style of development.) Each iteration advances the state of the application further. You can start following along with the book at the beginning of any iteration, using the code from the end of the previous iteration.

    The folders in the code zip file show the code at the end of each iteration. You can start at any iteration from 3–12 in this book by beginning with the code in the folder from the previous iteration; if you aren’t interested in following along with the early stuff but want to follow along starting with iteration 9, you should read iterations 1–8 and then start iteration 9 with the code from the iteration08 folder. You would rename the project from iteration08 to pomodo and import it using the same procedure as is shown next.

    Listing 3.7. app\controllers\application.rb
    # Filters added to this controller apply to all controllers in # the application. Likewise, all the methods added will be # available for all controllers. class ApplicationController < ActionController::Base helper :all # include all helpers, all the time include AuthenticatedSystem # See ActionController::RequestForgeryProtection for details # Uncomment the :secret if you're not using the cookie session # store # TODO - this will be uncommented once we explain sessions # in iteration 5. # protect_from_forgery # :secret => 'dd92c128b5358a710545b5e755694d57' end

    By adding the include AuthenticatedSystem here , we ensure that all controllers will include it by default (because they all extend ApplicationController). Furthermore, we temporarily comment out the protect_from_forgery call until iteration 5, because I don’t want to talk about CSRF attacks before having explained what a session is. Also note that your :secret will be different than this one—otherwise it wouldn’t be much of a :secret.

    If you’re starting here and wish to follow along, copy the appropriate folder of source code for iteration 2 (either iteration02_flexbuilder_windows, iteration02_sdk_mac or iteration02_sdk_windows) from the code zip file, paste it where you want to work, and rename it to current. If you’re using Flex Builder, edit the .project file with a text editor to rename the project from iteration02 to pomodo, as shown in listing 3.1.