IPAddr as Hash table key and accessing the mask_addr

N

ninj

Hi,

I'm using IPAddr objects as hash keys. So I need the hash and eql?
function as described in this post from the year 2004, which I'm
reposting below

It looks like a very simple and useful addition to the class. Could
someone please consider?

While we are on the subject of IPAddr... I also want to be able to
retrieve the netmask of the IP Address like this:

netrange = IPAddr.new "192.168.1.0/24"
netmask_of_netrange = netrange.mask_addr # => 24

I'm using the class as a nice IP address/netrange parser as well.

So, in all, I'm proposing a patch

class IPAddr
attr_reader :mask_addr
def hash
@addr
end
alias eql? ==
end

I can already do all these locally, but I thought it'd be sensible to
be included in the standard library. What do you think?

Nigel.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top