ipaddr icon indicating copy to clipboard operation
ipaddr copied to clipboard

== fails

Open rbur004 opened this issue 5 years ago • 2 comments

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

rbur004 avatar Oct 12 '19 19:10 rbur004

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)

rbur004 avatar Oct 12 '19 20:10 rbur004

Related issues in Ruby Issue Tracking System.

  • https://bugs.ruby-lang.org/issues/11531
  • https://bugs.ruby-lang.org/issues/1905

taketo1113 avatar Apr 29 '24 13:04 taketo1113