ipaddr
ipaddr copied to clipboard
== fails
Not sure if it is intended behaviour, but IPAddr.new('10.0.0.0/16') == IPAddr.new('10.0.0.0/8') is true, when these are not the same network. The test should be
def ==(value) @addr == value.addr && @mask_addr == value.mask_addr end Which also means adding attr_reader :addr attr_reader :mask_addr
I can see a case for the current code being right, in that they are the same ping-able IP address.
The problem is that IPAddr is trying to be both a representation of a network, and of a single IP address. It might be better to have an IPNet class that inherits from the IPAddr class, and check the masks in the IPNet case, and not the IPAddr case.
include? would be an interesting case, in that it could be checking that the IPAddr is in an IPNet, or it could check that an IPNet is a subnet of another IPNet (the argument's mask <= instance's mask)
Related issues in Ruby Issue Tracking System.
- https://bugs.ruby-lang.org/issues/11531
- https://bugs.ruby-lang.org/issues/1905