aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--lib/ipaddr.rb3
2 files changed, 8 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index d1b471fd20..ddf7adc6cb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat May 14 02:57:52 2011 Eric Hodel <drbrain@segment7.net>
+
+ * lib/ipaddr.rb (unless Socket): Document valid*? methods. Patch by
+ Sebastian Martinez. [Ruby 1.9 - Feature #4687]
+
Sat May 14 02:54:04 2011 Eric Hodel <drbrain@segment7.net>
* lib/rexml/functions.rb: Add some documentation for REXML::Functions.
diff --git a/lib/ipaddr.rb b/lib/ipaddr.rb
index 226a996021..9f6e6b8d38 100644
--- a/lib/ipaddr.rb
+++ b/lib/ipaddr.rb
@@ -23,6 +23,7 @@ unless Socket.const_defined? "AF_INET6"
end
class << IPSocket
+ # Returns +true+ if +addr+ is a valid IPv4 address.
def valid_v4?(addr)
if /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/ =~ addr
return $~.captures.all? {|i| i.to_i < 256}
@@ -30,6 +31,7 @@ unless Socket.const_defined? "AF_INET6"
return false
end
+ # Returns +true+ if +addr+ is a valid IPv6 address.
def valid_v6?(addr)
# IPv6 (normal)
return true if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*\Z/ =~ addr
@@ -43,6 +45,7 @@ unless Socket.const_defined? "AF_INET6"
false
end
+ # Returns +true+ if +addr+ is either a valid IPv4 or IPv6 address.
def valid?(addr)
valid_v4?(addr) || valid_v6?(addr)
end