Skip to content

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

Description

@patdowney

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?

Activity

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions