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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:36:44+00:00 2026-05-31T11:36:44+00:00

At Surface, Ruby appears to be quite similar to other object orieinted languages like

  • 0

At Surface,
Ruby appears to be quite similar to other object orieinted languages like Java,Php,C etc.

but, things get bit weird when we start to bump into blocks.

for example, this works

(0...8).max()
 => 7 

but this doesn’t

(0...8).map(puts "hello world")
hello world
ArgumentError: wrong number of arguments(1 for 0)

Apprantly, map method doesn’t take arguments but takes blocks, so passing replacing () with {} fix the error.

(0...8).map{puts "hello world"}
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
 => [nil, nil, nil, nil, nil, nil, nil, nil] 

And then, there are some methods should take both — blocks & arguments

8.downto(1){puts "hello world"}
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
 => 8 

The problem I have is the confusion on if I should be using () , {} or both on given method. On what basis it gets decided?

  • Is it fixed on per method basis & I just to have remember what the method takes(Blocks or params)?
  • Or is there any other logical reasoning on basis of which it gets decided, if the method takes blocks{} or params()?

Please help me understand

  • 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-31T11:36:45+00:00Added an answer on May 31, 2026 at 11:36 am

    Parenthesis after method calls are actually optional.

    (0...8).map{puts "hello world"} is equivalent to (0...8).map() {puts "hello world"}

    So you don’t really replace them.

    The acceptance of blocks is entirely up to the method, they can be specified in the method declaration:

    def method(param, &block)
      block.call
    end
    

    which will allow the block to be accessed as a variable from within the method, and be invoked via block.call for example.

    They can also be used implicitely via the use of the yield keyword:

    def method(param)
      yield
    end
    

    So you have to refer to the API documentations to be sure what is accepted or not.

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

Sidebar

Related Questions

i know nothing about ruby but a lot about php. when you code in
I've noticed many languages like Ruby and CofeeScript (well a transcompiler) support everything being
I have seen 3d surface plots of data before but i do not know
I'm using .NET to make an application with a drawing surface, similar to Visio.
I have a surface project and I would like to use controls designed in
I'm doing a Surface Application. And there I have something like a bulletin board
I've looked up surface plots and contour plots but cannot find the appropriate format.
I would like to generate random points on a 2D surface, distributed around a
This is a question relating to Microsoft Surface development, but I think it's more
On the surface it appears that python uses json natively. The only exception I

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.