From: "Jonas Pfenniger (zimbatm)" Date: 2011-01-07T03:48:36+09:00 Subject: Re: Block variable - How is it read in English? 2011/1/6 SW Engineer : > Following the "Ruby on Rails Tutorial", and under section "6.1.1 > Database migrations" > http://railstutorial.org/chapters/modeling-and-viewing-users-one#top > > There is the following migration: > > class CreateUsers < ActiveRecord::Migration >  def self.up >    create_table :users do |t| >      t.string :name >      t.string :email > . > . > . > > How do we read this line in English? > > create_table :users do |t| > > Why should we write the following line with "t."? > > t.string :name > > I know that block variables are used to pass parameters, but what is it > trying to tell us here? > > So the "do |t|" part is actually the part that is confusing me. > > Any clarifications would be appreciated. > > Thanks. The do..end notation is the syntax to describe a block. Blocks can also be written with the {...} notation, which is equivalent. create_table :users {|t|  t.string :name  t.string :email } create_table will accept two arguments, the :users symbol, and the block. notice there is no comma between the two arguments, this is because blocks have a special status, they are only described as the last argument of a function-call. the block in turn, is like a function, but that has no name. instead of defining arguments with the (...) notation, it uses this special |...| notation. when create_table is called with those two arguments, it will itself call the block, and provide an object, that we named 't'. t.string further calls the string function on the t argument. I hope I made it a bit clearer, but if I didn't persist. Once you understand this, you will feel much more empowered :) Also, I see you took the example from the old Pickaxe book. It doesn't do a really good job of explaining blocks, so maybe it's worth to buy the new edition. This seems to be a good introduction too: http://eli.thegreenplace.net/2006/04/18/understanding-ruby-blocks-procs-and-methods/