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

  • Home
  • SEARCH
  • 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 310979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:52:59+00:00 2026-05-12T07:52:59+00:00

I have a couple questions about Ruby’s methods, procedures, and blocks that strike me

  • 0

I have a couple questions about Ruby’s methods, procedures, and blocks that strike me as rather odd. They’re not so much about syntax or function as the logic behind the decisions made.

Question 1:

Why is it that blocks can be passed to methods (e.g. each) but they cannot be assigned to a variable?

I know you can pass them around in procedures, i.e. p = Proc.new {...} (accessed with &p), but it doesn’t make much sense to make the programmer go through these means.

Question 2:

Why is there a differentiation between methods and procedures?

For instance, I can accomplish the task of defining a function and calling that function in the following two ways:

def square(x)
    x**2
end

square(3)
=> 9

or

square = lambda {|x| x**2}
square.call(3)
=> 9

Why the differentiation? In Python for example both defining a function in the standard way and by square = lambda x: x**2 accomplish the same task of creating the function and assigning it to square.

  • 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-12T07:52:59+00:00Added an answer on May 12, 2026 at 7:52 am

    Question 1: Blocks are not objects, they are syntactic structures; this is why they cannot be assigned to a variable. This is a privilege reserved for objects.

    Question 2: Methods are not objects, so they cannot receive messages. Inversely, procs and lambdas are objects, so they cannot be invoked like methods, but must receive a message that tells them to return a value on the basis of the parameters passed with the message.

    Procs and Lambdas are objects, so they can receive the call message and be assigned to names. To summarize, it is being an object that makes procs and lambdas behave in ways you find odd. Methods and blocks are not objects and don’t share that behavior.

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

Sidebar

Related Questions

I have a couple of questions about generic wildcards in Java: What is the
I am a newbie to WPF and have a couple of questions about WPF
There have been a couple of questions that sort of dealt with this but
I've found a couple of questions about embedding Ruby in a C++ app. Almost
I have a couple of questions regarding VBScript and ASP Classic: What is the
Possible Duplicate: Split string in SQL I have seen a couple of questions related
This follows a couple of other questions (but I think I have refined my
I have a couple old services that I want to completely uninstall. How can
I'll have couple of python functions I must interface with from the assembly code.
I have a couple of files containing a value in each line. EDIT :

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.