Permalink
Browse files

Make IP instances freeze-friendly

  • Loading branch information...
Étienne Barrié
Étienne Barrié committed Jan 12, 2011
1 parent 9683694 commit c25f81476482bc12340d3ff67b33c661b47e495b
Showing with 35 additions and 0 deletions.
  1. +5 −0 lib/ip/base.rb
  2. +30 −0 test/ip_test.rb
View
@@ -247,6 +247,11 @@ def hash
to_a.hash
end
+ def freeze
+ mask
+ super
+ end
+
def eql?(other)
to_a.eql?(other.to_a)
end
View
@@ -476,6 +476,36 @@ class IPTest < Test::Unit::TestCase
end
end
+ context "freezing" do
+ setup do
+ @addr = IP.new('1.2.3.4/24@foo').freeze
+ end
+
+ should "be able to get values without a TypeError" do
+ assert_nothing_raised(TypeError) do
+ @addr.to_s
+ @addr.to_addrlen
+ @addr.to_addr
+ @addr.to_i
+ @addr.to_a
+ @addr.to_ah
+ @addr.to_hex
+ @addr.pfxlen
+ @addr.proto
+ @addr.to_irange
+ @addr.to_range
+ @addr.size
+ @addr.ctx
+ @addr.network
+ @addr.broadcast
+ @addr.mask
+ @addr.netmask
+ @addr.wildmask
+ @addr.offset
+ end
+ end
+ end
+
context "range between two IPs" do
should "be able to iterate" do
r = IP.new("10.0.0.6")..IP.new("10.0.0.8")

0 comments on commit c25f814

Please sign in to comment.