IPAddr as Hash table key and accessing the mask_addr


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 “”
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
alias eql? ==

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?


On Jan 12 2004, 4:54 pm, Neil S. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs