From f347a9212e20e437436405e097be828b63554c02 Mon Sep 17 00:00:00 2001 From: drbrain Date: Fri, 13 May 2011 17:59:35 +0000 Subject: [PATCH] * 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 --- ChangeLog | 5 +++++ lib/ipaddr.rb | 3 +++ 2 files changed, 8 insertions(+) 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 + + * 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 * 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