summaryrefslogtreecommitdiff
path: root/lib/ipaddress/ipv4.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ipaddress/ipv4.rb')
-rw-r--r--lib/ipaddress/ipv4.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/ipaddress/ipv4.rb b/lib/ipaddress/ipv4.rb
index 500531a..7d8e0d3 100644
--- a/lib/ipaddress/ipv4.rb
+++ b/lib/ipaddress/ipv4.rb
@@ -286,6 +286,21 @@ module IPAddress;
@octets[index]
end
alias_method :octet, :[]
+
+ #
+ # Updated the octet specified at index
+ #
+ # ip = IPAddress("172.16.100.50/24")
+ # ip[2] = 200
+ #
+ # #=> #<IPAddress::IPv4:0x00000000000000 @address="172.16.200.1",
+ # #=> @prefix=32, @octets=[172, 16, 200, 1], @u32=2886780929>
+ #
+ def []=(index, value)
+ @octets[index] = value.to_i
+ initialize("#{@octets.join('.')}/#{prefix}")
+ end
+ alias_method :octet=, :[]=
#
# Returns the address portion of an IP in binary format,