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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:31:44+00:00 2026-06-04T15:31:44+00:00

I am calling sort on an array like this: new_list = my_array.sort The error

  • 0

I am calling sort on an array like this:

new_list = my_array.sort

The error I am getting is:

NoMethodError: undefined method `<=>' for nil:NilClass

How do I handle nil cases for this simple sort?

I initially had a destructive sort call (i.e. sort!) and changed it to the regular sort, but it still throws this error.

Thoughts?

  • 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-04T15:31:46+00:00Added an answer on June 4, 2026 at 3:31 pm

    Well, I assume you don’t need/want the nils, so…

    new_list = my_array.compact.sort
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a sort of generic xml parser, like this: Part
By this I mean when calling .push() on an Array object and JavaScript increases
I've adapted QuickSort Method to sort Array's Row. Here's the code: That one works
I'm calling Arrays.sort(schedule, c); where c is an instance of a comparator like so:
My array looks like this: Array ( [0] => Array ( [0] => 1
Calling the ajax called URL works well without ajax eg. http://localhost/ci/controller/method/param_value . But using
Calling getActionBar returns null . This has been frequently reported so I've made sure
I'm trying to pre-sort an array of items are added into an array using
Hello I have an array of persons, and i am trying to sort them
I have a set of classes something like this: abstract class CollectionAbs implements Iterator

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.