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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:35:32+00:00 2026-05-27T10:35:32+00:00

I have a very strange problem with #any? printing true for an array that

  • 0

I have a very strange problem with #any? printing true for an array that only has nil objects.

The background: This is all taking part in the model – I have a list of records in an array and I set the array’s element to nil if the indexed item matches certain criteria. Because I was not getting the results I was expecting (writing tests), I whacked in some debugging.

logger.debug "SIZE #{my_event_type_time_units.size}"
logger.debug "CLASS #{my_event_type_time_units.class}"
my_event_type_time_units.each { |r| logger.debug "#{r.class}" }
logger.debug "ANY? #{my_event_type_time_units.any?}"

Output

SIZE 3
CLASS Array
NilClass
NilClass
NilClass
ANY? true

As an aside, when I tried the any? with a list of nil objects, it returned false.

[nil, nil, nil].any? ## false

Can anyone tell me what I’m doing wrong. This is my first time using #any? but it can’t be that hard. Can it?

any? will return true if at least one of the collection members is not false or nil
  • 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-27T10:35:33+00:00Added an answer on May 27, 2026 at 10:35 am

    You are looking at Ruby’s implementation of any?, not Rails. Remember that Rails associations (specifically Arel associations) are NOT actual arrays… they are more sophisticated than that. Anything you return from a model is an association, not an array. Rails monkey-patches things to make them behave like regular Ruby objects (such has .class returning Array, but that is not always the case. Here’s Rail’s code for any?:

    # activerecord/lib/active_record/associations/collection_association.rb, line 268
    def any?
      if block_given?
        load_target.any? { |*block_args| yield(*block_args) }
      else
        !empty?
      end
    end
    

    And here’s Ruby’s:

    static VALUE
    enum_any(VALUE obj)
    {
        VALUE result = Qfalse;
    
        rb_block_call(obj, id_each, 0, 0, ENUMFUNC(any), (VALUE)&result);
        return result;
    }
    

    They behave differently.

    I’m not sure what you are trying to accomplish, but I suspect that any? is not the right method. I would suggest looking into include? or even compact…

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

Sidebar

Related Questions

Very strange problem with my iPhone App. We have an App that has been
Im having a very strange problem, i have a complicated view that returns incorrect
I have a very strange error happening in an App that has been working
I have a rather strange problem. I have a very simple application that reads
I have this very strange problem on a big flex app where it would
I have a very strange problem: The instance of my DTO that is non-null
I have a very strange problem that I cannot solve. There is something preventing
I have a very strange issue that only affects webkit browsers for some reason,
We have very strange problem, one of our applications is continually querying server by
I have a very strange problem. Under some elusive circumstances I fail to apply

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.