mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
8dca379907
commit
f347a9212e
2 changed files with 8 additions and 0 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue