Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3849070
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:47:53+00:00 2026-05-19T16:47:53+00:00

I`m new to rails, so that question may be stupid. I have seen a

  • 0

I`m new to rails, so that question may be stupid.
I have seen a lot of code like this

method do |x|
 x.something
 x.blabla
end

For example some snippet from migrate

create_table :users do |t|
      t.string :name
      t.string :email

      t.timestamps
    end  

What happens here ? |t| is passed to create_table method or ?
I can`t fugure out

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T16:47:54+00:00Added an answer on May 19, 2026 at 4:47 pm

    The |x| is a parameter being passed to the block. It is a feature of Ruby, not specific to Ruby on Rails.

    Here’s a very contrived example of how you might implement a function which accepts a block:

    # invoke proc on each element of the items array
    def each(items, &proc)
      for i in (0...items.length)
        proc.call(items[i])
      end
    end
    
    my_array = [1,2,3];
    
    # call 'each', passing in items and a block which prints the element
    each my_array do |i|
      puts i
    end
    

    Effectively, you’re invoking each and passing it two things: An array (my_array) and a block of code to execute. Internally each loops over each item in the array and invokes the block on that item. The block receives a single parameter, |i|, which is populated by each when it calls proc: proc.call(items[i]).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok...I am new to rails so this may be a stupid question but need
Im new to rails so this may seem like a silly question but why
Please bear in mind that I'm totally new to Rails when answering this.My question
I am pretty new to rails so this may be an easy question, but
I'm pretty new to rails, so this may be a dumb question, but I'm
I'm new to rails, so please excuse me for that possibly very stupid question.
I'm new to rails, so this might seem like a dumb question. I want
I have a question about models on Ruby on Rails: I have this method
new on rails and using windows for now,, i have web page that user
I am new to rails. What I see that there are a lot of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.