From 89cc3cc8f71cb3fe823698e4d71c27f98d26c01d Mon Sep 17 00:00:00 2001
From: Mike Mackintosh <m@zyp.io>
Date: Mon, 23 Mar 2015 17:15:49 -0400
Subject: [PATCH] added IPv6#[]= to fix #24

---
 lib/ipaddress/ipv6.rb       | 9 +++++++++
 test/ipaddress/ipv6_test.rb | 8 +++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

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
-- 
GitLab