diff options
-rw-r--r-- | lib/ipaddress/ipv6.rb | 9 | ||||
-rw-r--r-- | test/ipaddress/ipv6_test.rb | 8 |
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/ipaddress/ipv6.rb b/lib/ipaddress/ipv6.rb index 33d4d19..88098bc 100644 --- a/lib/ipaddress/ipv6.rb +++ b/lib/ipaddress/ipv6.rb @@ -252,6 +252,15 @@ module IPAddress; end alias_method :group, :[] + # + # Updated the octet specified at index + # + def []=(index, value) + @groups[index] = value + initialize("#{IN6FORMAT % @groups}/#{prefix}") + end + alias_method :group=, :[]= + # # Returns a Base16 number representing the IPv6 # address diff --git a/test/ipaddress/ipv6_test.rb b/test/ipaddress/ipv6_test.rb index f0932d7..dcfb601 100644 --- a/test/ipaddress/ipv6_test.rb +++ b/test/ipaddress/ipv6_test.rb @@ -292,6 +292,12 @@ class IPv6Test < Minitest::Test assert_equal @ip.to_s, @klass.parse_hex(@hex,64).to_s end + def test_group_updates + ip = @klass.new("2001:db8::8:800:200c:417a/64") + ip[2] = '1234' + assert_equal "2001:db8:4d2:0:8:800:200c:417a/64", ip.to_string + end + end # class IPv6Test class IPv6UnspecifiedTest < Minitest::Test @@ -416,5 +422,5 @@ class IPv6MappedTest < Minitest::Test def test_mapped? assert_equal true, @ip.mapped? end - + end # class IPv6MappedTest |