Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

== fails #21

Open
rbur004 opened this issue Oct 12, 2019 · 2 comments
Open

== fails #21

rbur004 opened this issue Oct 12, 2019 · 2 comments

Comments

@rbur004
Copy link

rbur004 commented Oct 12, 2019

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
Copy link
Author

rbur004 commented Oct 12, 2019

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)

@taketo1113
Copy link
Contributor

Related issues in Ruby Issue Tracking System.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants