1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/ipaddr] Add netmask method that returns net mask as string.

https://github.com/ruby/ipaddr/commit/283d16f3a3
This commit is contained in:
Bogdan Irimie 2019-10-09 13:23:27 +03:00 committed by Hiroshi SHIBATA
parent abad5e10e8
commit 74ed881e10
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
2 changed files with 16 additions and 0 deletions

View file

@ -466,6 +466,11 @@ class IPAddr
af, _to_string(@addr), _to_string(@mask_addr))
end
# Returns the netmask in string format e.g. 255.255.0.0
def netmask
_to_string(@mask_addr)
end
protected
# Set +@addr+, the internal stored ip address, to given +addr+. The

View file

@ -220,6 +220,17 @@ class TC_IPAddr < Test::Unit::TestCase
assert_equal("3ffe:0505:0002:0000:0000:0000:0000:0001", IPAddr.new("3ffe:505:2::1").to_string)
assert_equal("3ffe:505:2::1", IPAddr.new("3ffe:505:2::1").to_s)
end
def test_netmask
a = IPAddr.new("192.168.1.2/8")
assert_equal(a.netmask, "255.0.0.0")
a = IPAddr.new("192.168.1.2/16")
assert_equal(a.netmask, "255.255.0.0")
a = IPAddr.new("192.168.1.2/24")
assert_equal(a.netmask, "255.255.255.0")
end
end
class TC_Operator < Test::Unit::TestCase