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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:24:37+00:00 2026-06-08T07:24:37+00:00

Possible Duplicate: When to use lambda, when to use Proc.new? (I know it had

  • 0

Possible Duplicate:
When to use lambda, when to use Proc.new?

(I know it had been asked several times but I couldn’t find satisfactory answer)Can somebody please explain Blocks, Procs and Lambdas and why one should be used over other, what are the situation when one should use proc, similar and/or lambda. Also there effect on computer memory. Practical examples please.

  • 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-08T07:24:38+00:00Added an answer on June 8, 2026 at 7:24 am

    Try Robert Sosinski’s Tutorial or Learning to Program by Chris Pine.

    For more foundation I suggest you read Why’s (poignant) Guide to Ruby. This guide is responsible for creating many of nowadays Ruby’s Pro! Make sure to take a look!


    Explanation by Joey deVilla

    Another important but subtle difference is in the way procs created with lambda and procs created with Proc.new handle the return statement:

    • In a lambda-created proc, the return statement returns only from the proc itself
    • In a Proc.new-created proc, the return statement is a little more surprising: it returns control not just from the proc, but also from the method enclosing the proc!

    Here’s lambda-created proc’s return in action. It behaves in a way that you probably expect:

    def whowouldwin
    
      mylambda = lambda {return "Freddy"}
      mylambda.call
    
      # mylambda gets called and returns "Freddy", and execution
      # continues on the next line
    
      return "Jason"
    
    end
    
    
    whowouldwin
    => "Jason"
    

    Now here’s a Proc.new-created proc’s return doing the same thing. You’re about to see one of those cases where Ruby breaks the much-vaunted Principle of Least Surprise:

    def whowouldwin2
    
      myproc = Proc.new {return "Freddy"}
      myproc.call
    
      # myproc gets called and returns "Freddy", 
      # but also returns control from whowhouldwin2!
      # The line below *never* gets executed.
    
      return "Jason"
    
    end
    
    
    whowouldwin2         
    => "Freddy"
    

    Thanks to this surprising behaviour (as well as less typing), I tend to favour using lambda over Proc.new when making procs.

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

Sidebar

Related Questions

Possible Duplicate: Bind Vs Lambda? My use of std::bind had dropped to 0 now
Possible Duplicate: Why use pointers? I know what the C++ & does. but what
Possible Duplicate: Why use getters and setters? I know this is very trivial. But
Possible Duplicate: Inadvertent use of = instead of == C++ compilers let you know
Possible Duplicate: Use of var keyword in C# Being relatively new to C# I
Possible Duplicate: To use Wordpress for developing a web application? For instance, I've been
Possible Duplicate: Why is it bad to use a iteration variable in a lambda
Possible Duplicate: Why use getters and setters? Yes, It's a very simple thing but
Possible Duplicate: Why not use tables for layout in HTML? I know everyone is
Possible Duplicate: Use of .apply() with 'new' operator. Is this possible? I have 5

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.