IPv? and Prefix? classes don't work as expected in hashes and sets #21

Open
patdowney opened this Issue May 29, 2012 · 1 comment

Comments

Projects
None yet
2 participants

In the following examples I would expect the set to only have one entry and the hash to only have one key (note: if it's the same object instance you won't see this behaviour).

require 'set'
require 'ipaddress'

# works as expected
net =  IPAddress.parse('192.168.0.0/24')
s = Set.new
s.add net
s.add net
puts s.length # => 1

# doesn't work as expected
s = Set.new
s.add IPAddress.parse('192.168.0.0/24')
s.add IPAddress.parse('192.168.0.0/24')
puts s.length # => 2, should be 1?

# likewise with hashes
# works as expected
net =  IPAddress.parse('192.168.0.0/24')
h = {}
h[net] = true
h[net] = false
puts h.length # => 1

# doesn't work as expected
h = {}
h[IPAddress.parse('192.168.0.0/24')] = true
h[IPAddress.parse('192.168.0.0/24')] = false
puts h.length # => 2, should be 1?

Pull request with fix raised (Issue #22)

@mikemackintosh mikemackintosh self-assigned this Mar 24, 2015

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