Can you explain what's going on in this Ruby code?

Posted by samoz on Stack Overflow See other posts from Stack Overflow or by samoz
Published on 2009-07-04T17:52:20Z Indexed on 2010/03/28 19:23 UTC
Read the original article Hit count: 258

Filed under:
|

I'm trying to learn Ruby as well as Ruby on Rails right now. I'm following along with Learning Rails, 1st edition, but I'm having a hard time understanding some of the code.

I generally do work in C, C++, or Java, so Ruby is a pretty big change for me.

I'm currently stumped with the following block of code for a database migrator:

  def self.up
    create_table :entries do |t|
      t.string :name
      t.timestamps
    end
  end

Where is the t variable coming from? What does it actually represent? Is it sort of like the 'i' in a for(i=0;i<5;i++) statement?

Also, where is the :entries being defined at? (entries is the name of my controller, but how does this function know about that?)

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails