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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:44:26+00:00 2026-06-13T21:44:26+00:00

First of all I found two useful articles in documentations about these methods: http://www.ruby-doc.org/core-1.9.3/Enumerable.html

  • 0

First of all I found two useful articles in documentations about these methods:

  • http://www.ruby-doc.org/core-1.9.3/Enumerable.html
  • http://www.globalnerdy.com/2008/01/29/enumerating-rubys-enumerable-module-part-1-all-and-any/

all?: Passes each element of the collection to the given block. The method returns true if the block never returns false or nil.

any?: Passes each element of the collection to the given block. The method returns true if the block ever returns a value other than false or nil.

But in case of empty arrays and hashes I got:

irb(main):004:0> [nil, "car", "bus"].all?
=> false
irb(main):005:0> ["nil", "car", "bus"].all?
=> true
irb(main):006:0> [].all?
=> true
irb(main):007:0> ["nil", "car", "bus"].any?
=> true
irb(main):008:0> [nil, "car", "bus"].any?
=> true
irb(main):009:0> [nil].any?
=> false
irb(main):010:0> [].any?
=> false

Can somebody explain to me why empty arrays give me false in case of the any? method and true in case of all??

  • 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-13T21:44:27+00:00Added an answer on June 13, 2026 at 9:44 pm

    The method returns true if the block never returns false or nil.

    So since the block never gets called, of course it never returns false or nil, thus all returns true.

    The same goes for any:

    The method returns true if the block ever returns a value other than
    false or nil.

    Since the block never gets called, it never returns a value other than false or nil, thus any returns false.

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

Sidebar

Related Questions

I'm new here, just found these forums on Google. First of all, I want
First of all, I found this: Objective C HTML escape/unescape , but it doesn't
I found this on a website, css_loader.php <?php // First of all send css
First of all, apologize because I have seen some posts about this, but I
First of all I want to mention two things, One: My code isn't perfect
All I have found about this is that there are inconsistencies among different web
I have to concatenate these two strings from my resource/value files: <string name=Toast_Memory_GameWon_part1>you found
First of all I'm sorry if this is a stupid question. I've written two
First of all, this isn't for a keylogger, it's for an input in a
first of all some details: I configured security as below in web.xml view plaincopy

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.