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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:37:25+00:00 2026-05-25T14:37:25+00:00

I found out from heckle that [1, 2, 3].each(&nil) doesn’t cause any errors –

  • 0

I found out from heckle that

[1, 2, 3].each(&nil)

doesn’t cause any errors – it just returns an enumerator.

By contrast,

[1, 2, 3].each(&"")

raises

TypeError: wrong argument type String (expected Proc)

Also, &nil causes block_given? to return false

def block_given_tester
  if block_given?
    puts "Block given"
  else
    puts "Block not given"
  end
end

block_given_tester(&nil) # => Block not given

It’s not because NilClass implements to_proc – I checked the RDoc.

I can understand why it’d be nice to have &nil, but I’m not sure how it’s done. Is this just one of the ways nil has special behavior not shared by other objects?

  • 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-25T14:37:25+00:00Added an answer on May 25, 2026 at 2:37 pm

    The answer can be found by looking at Ruby’s source code.

    Ruby 1.8:

    Look at the function block_pass in the file eval.c. Note that it treats nil specially from Proc objects (the macro NIL_P). If the function is passed a nil value, it evaluates an empty block (I think) and returns. The code right after it checks whether the object is a Proc object (the function rb_obj_is_proc) and raises the exception “wrong argument type (expected Proc)” if it isn’t.

    Ruby 1.9.2:

    Look at the method caller_setup_args in the file vm_insnhelper.c. It converts the proc with to_proc only
    if it is not nil; otherwise, the type conversion and type check are bypassed.

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

Sidebar

Related Questions

I just found out that lazy loading in Entity Framework only works from the
I've just found out that a spammer is sending email from our domain name,
From the Jobeet tutorial provided in Symfony website, I found out that I can
I want to live stream video from android device. I found out that ffserver
When exporting some data from MS SQL Server using Python, I found out that
First sorry for the english. I've recently found out that the MessageBox from Windows.Forms
I found out randomly that when browsing an SVN repository from a web browser
I’ve just found out that the execution plan performance between the following two select
I just found out this code from a tutorial for matrix addition in c++
I just found out that there is no generator for Arabic fonts, because of

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.