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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:05:33+00:00 2026-05-31T03:05:33+00:00

In venturing into Ruby , I started toying with things like the way Ruby

  • 0

In venturing into Ruby, I started toying with things like the way Ruby returns the last thing you’ve mentioned even if it was not after a return construct. However, why don’t these two snippets work the same way? Shouldn’t they?

module Enumerable
  def palindrome?
    reversed_self = self.reverse
    self.each_with_index {|el,index|
      unless self[index]==reversed_self[index]
        return false ## <-----
      end
    }
    true
  end
end

all good so far: puts [‘foo’,’bar’,’baz’].palindrome? prints ‘false’

and

module Enumerable
  def palindrome?
    reversed_self = self.reverse
    self.each_with_index {|el,index|
      unless self[index]==reversed_self[index]
        false ## <------
      end
    }
    true
  end
end

puts [‘foo’,’bar’,’baz’].palindrome? prints ‘true’ for some reason

What’s the science behind this?

  • 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-31T03:05:34+00:00Added an answer on May 31, 2026 at 3:05 am

    Not quite! A return from inside a block is different from a return inside a lambda, as mentioned in my answer here. When you return from inside a block, you’re returning from the entire method rather than just the block.

    We can illustrate this as follows:

    return :foo # => LocalJumpError: unexpected return
    [1, 2, 3].map { return :foo } # => LocalJumpError: unexpected return
    [1, 2, 3].map { :foo } # => [:foo, :foo, :foo]
    

    Normally, this doesn’t happen with lambdas:

    l = lambda { return :foo }
    l.call # => :foo
    [1, 2, 3].map { l.call } # => [:foo, :foo, :foo]
    

    But when we try to pass the lambda as a block to the method, the behavior changes back:

    [1, 2, 3].map &l # => LocalJumpError: unexpected return
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently started venturing into some HP webOS development and I am wondering
I'm venturing into the world of asp.net mvc. I have not yet understood whether
I'm venturing into making my VB.NET application a little better to use by making
I'm venturing into the world of C++ and Linux, and am having problems linking
I'm venturing out of the world of .NET and into the world of open-source.
If you had a differential of either venturing into Delphi land or Qt land
I am a PHP/MySQL developer, slowly venturing into the realm of C#/SQL Server and
I am venturing into the world of setting up cronjobs and trying to learn
Venturing out of my usual VC++ realm into the world of GCC (via MINGW32).
Some background.... We're venturing into Azure for the first time and are trying to

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.