summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-13 17:59:35 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-13 17:59:35 +0000
commitf347a9212e20e437436405e097be828b63554c02 (patch)
tree4e6b3d59592400b61327bf51d2568ee1535a68d2
parent8dca37990791a5572e7f7df7bbc9a0ab5aa5d8da (diff)
* lib/ipaddr.rb (unless Socket): Document valid*? methods. Patch by
Sebastian Martinez. [Ruby 1.9 - Feature #4687] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31552 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--lib/ipaddr.rb3
2 files changed, 8 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index d1b471fd20d..ddf7adc6cba 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 226a9960212..9f6e6b8d38a 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