summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Mackintosh <m@zyp.io>2015-03-23 17:15:49 -0400
committerMike Mackintosh <m@zyp.io>2015-03-23 17:15:49 -0400
commit89cc3cc8f71cb3fe823698e4d71c27f98d26c01d (patch)
tree9f23929cff46f9cd4c2fb0aec8339665051cef95
parentad087f8fac02c9de49ef78263a376d20e442ac2a (diff)
downloadipaddress-89cc3cc8f71cb3fe823698e4d71c27f98d26c01d.tar.gz
added IPv6#[]= to fix #24
-rw-r--r--lib/ipaddress/ipv6.rb9
-rw-r--r--test/ipaddress/ipv6_test.rb8
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