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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:39:11+00:00 2026-06-17T09:39:11+00:00

I am trying to sort some ip addresses in ascending order using ipaddr. Not

  • 0

I am trying to sort some ip addresses in ascending order using ipaddr. Not sure why this is not working. After I run my custom sort, the order is not affected.

require 'ipaddr'
ip_array = Array.new
ip_array2 = Array.new

ip_array = ["d1.mysite.com",
            "d3.mysite.com",
            "d2.mysite.com",
            "d6.mysite.com",
            "d32.mysite.com",
            "d5.mysite.com",
            "d9.mysite.com",
            "d34.mysite.com"]



 ## First, get IP addresses and push onto ip_array2
 ip_array.each { |x| ip_array2.push(IPSocket::getaddress(x))  }

 ## Let's see the unsorted array contents
 ip_array2.each { |x| puts x }


 ## Now, sort IP addresses in ip_array2
 ip_array2.sort { |a,b| IPAddr.new( a ) <=> IPAddr.new( b ) } 

 ## Let's see the sorted array contents
 ip_array2.each { |x| puts x }

BEFORE SORT (1st 3 octets are identical)

xxx.xx.xx.78
xxx.xx.xx.114
xxx.xx.xx.54
xxx.xx.xx.57
xxx.xx.xx.58
xxx.xx.xx.79
xxx.xx.xx.81
xxx.xx.xx.100

AFTER SORT (1st 3 octets are identical)

xxx.xx.xx.78
xxx.xx.xx.114
xxx.xx.xx.54
xxx.xx.xx.57
xxx.xx.xx.58
xxx.xx.xx.79
xxx.xx.xx.81
xxx.xx.xx.100
  • 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-17T09:39:12+00:00Added an answer on June 17, 2026 at 9:39 am

    sort is not in place. Either call sort! or assign the result from sort to ip_array2.

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

Sidebar

Related Questions

I'm debugging this site and trying to sort out some issues that arise in
i'm trying to make some sort of Business Simulation Game and everything is working
Not sure if this question makes for some poor performance down the track, but
I'm using NHibernate as my ORM and I'm trying to sort some data. The
Can anyone help me, I am trying to sort out some redirects using htaccess
I am trying to impose some sort of semantic logic for the default values
I'm trying to do some sort of strange Facebook App which notifies developers of
I'm trying to make some sort of delay in the view controllers changing. I
I'm trying to create some sort of timeline view like in video editors: media
I am trying to build some sort of a javascript antivirus that would try

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.