Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/ipaddr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ class Socket < BasicSocket
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}
end
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
Expand All @@ -43,6 +45,7 @@ def valid_v6?(addr)
false
end

# Returns +true+ if addr is either a valid IPv4 or IPv6 address.
def valid?(addr)
valid_v4?(addr) || valid_v6?(addr)
end
Expand Down
10 changes: 9 additions & 1 deletion numeric.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,15 @@ flo_to_s(VALUE flt)
}

/*
* MISSING: documentation
* call-seq:
* flt.flo_coerce(numeric) -> array
*
* Returns an array with both <i>aNumeric</i> and <i>flt</i> represented
* as <code>Float</code> objects.
* This is achieved by converting <i>aNumeric</i> to a <code>Float</code>.
*
* 1.2.coerce(3) #=> [3.0, 1.2]
* 2.5.coerce(1.1) #=> [1.1, 2.5]
*/

static VALUE
Expand Down