On Jan 16, 2008, at 12:02 AM, Bryan Richardson wrote:

> Hello all,
>
> I'm having a problem with IPAddr, and I'm hoping someone can  
> explain it to
> me.  I've done the following test, and I get the results shown below.
>
> irb(main):001:0> require 'ipaddr'
> => true
> irb(main):002:0> net_1 = IPAddr.new("192.168.0.0/16")
> => #<IPAddr: IPv4:192.168.0.0/255.255.0.0>
> irb(main):003:0> net_2 = IPAddr.new("192.168.0.0/24")
> => #<IPAddr: IPv4:192.168.0.0/255.255.255.0>
> irb(main):004:0> net_1.include?(net_2)
> => true
> irb(main):005:0> net_2.include?(net_1)
> => true
> irb(main):006:0>

It is because include? is treating its argument as an address not as  
a network.  The subnet mask of the argument is ignored.  So   
net_2.include?(net_1) is really asking whether the first address of  
net_1 (192.168.0.0) is contained in net_2 and that is true.

Gary Wright