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 7918943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:41:08+00:00 2026-06-03T15:41:08+00:00

I’m getting to grips with rails and whilst I feel I am progressing there

  • 0

I’m getting to grips with rails and whilst I feel I am progressing there is one thing that I am struggling to get to grips with and it’s very basic. I am trying to understand the different usage of [] {} and () Are there any good sources of their usage and are there any tips you can give to a beginner in recognizing when to use one or the other, or as I seem to see in some cases when they are not required at all?
I know this is extremely basic but I have struggled to find literature which explains concisely the interplay between them and Ruby or specifically RoR

  • 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-06-03T15:41:10+00:00Added an answer on June 3, 2026 at 3:41 pm

    It has nothing to do with RoR; the various brackets are Ruby language constructs.

    [] is the array operator, for arrays and other classes that implement it (like a string taking a range to get substrings, or hashes to look up a key’s value):

    a = [1, 2, 3]
    a.each { |n| puts n }
    
    s = "ohai"
    puts s[1..-1]
    
    h = { foo: "bar", baz: "plugh" }
    puts h[:foo]
    

    {} is for hashes, and one of two ways of delimiting blocks (the other being begin/end). (And used with # for string interpolation.)

    h = { foo: "bar", baz: "plugh" }
    h.each { |k, v| puts "#{k} == #{v}" }
    

    () is for method parameters, or for enforcing evaluation order in an expression.

     > puts 5 * 3 + 5     # Normal precedence has * ahead of +
    => 20
     > puts 5 * (3 + 5)   # Force 3+5 to be evaluated first
    => 40
    
    def foo(s)
      puts(s)
    end
    

    They’re sometimes optional if the statement has no ambiguity:

    def foo s
      puts s
    end
    

    (They’re not always optional, and putting a space between the method call and its parenthetical parameter list can cause issues–best not to, IMO.)

    (I probably missed something, too, but there’s the nutshell.)

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build

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.