lib/ipaddress.rb in ipaddress-0.7.0 vs lib/ipaddress.rb in ipaddress-0.7.5
- old
+ new
@@ -20,11 +20,11 @@
module IPAddress
NAME = "IPAddress"
GEM = "ipaddress"
AUTHORS = ["Marco Ceresa <ceresa@ieee.org>"]
-
+
#
# Parse the argument string to create a new
# IPv4, IPv6 or Mapped IP object
#
# ip = IPAddress.parse "172.16.10.1/24"
@@ -46,9 +46,33 @@
when /:.+\./
IPAddress::IPv6::Mapped.new(str)
else
IPAddress::IPv4.new(str) rescue IPAddress::IPv6.new(str)
end
+ end
+
+ #
+ # True if the object is an IPv4 address
+ #
+ # ip = IPAddress("192.168.10.100/24")
+ #
+ # ip.ipv4?
+ # #-> true
+ #
+ def ipv4?
+ self.kind_of? IPAddress::IPv4
+ end
+
+ #
+ # True if the object is an IPv6 address
+ #
+ # ip = IPAddress("192.168.10.100/24")
+ #
+ # ip.ipv6?
+ # #-> false
+ #
+ def ipv6?
+ self.kind_of? IPAddress::IPv6
end
#
# Checks if the given string is a valid IP address,
# either IPv4 or IPv6