Skip to content
Merged
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
34 changes: 15 additions & 19 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1789,72 +1789,68 @@ static VALUE rb_ary_aref2(VALUE ary, VALUE b, VALUE e);

/*
* call-seq:
* self[index] -> object or nil
* self[start, length] -> object or nil
* self[offset] -> object or nil
* self[offset, size] -> object or nil
* self[range] -> object or nil
* self[aseq] -> object or nil
* slice(index) -> object or nil
* slice(start, length) -> object or nil
* slice(range) -> object or nil
* slice(aseq) -> object or nil
*
* Returns elements from +self+; does not modify +self+.
*
* In brief:
*
* a = [:foo, 'bar', 2]
*
* # Single argument index: returns one element.
* # Single argument offset: returns one element.
* a[0] # => :foo # Zero-based index.
* a[-1] # => 2 # Negative index counts backwards from end.
*
* # Arguments start and length: returns an array.
* # Arguments offset and size: returns an array.
* a[1, 2] # => ["bar", 2]
* a[-2, 2] # => ["bar", 2] # Negative start counts backwards from end.
* a[-2, 2] # => ["bar", 2] # Negative offset counts backwards from end.
*
* # Single argument range: returns an array.
* a[0..1] # => [:foo, "bar"]
* a[0..-2] # => [:foo, "bar"] # Negative range-begin counts backwards from end.
* a[-2..2] # => ["bar", 2] # Negative range-end counts backwards from end.
*
* When a single integer argument +index+ is given, returns the element at offset +index+:
* When a single integer argument +offset+ is given, returns the element at offset +offset+:
*
* a = [:foo, 'bar', 2]
* a[0] # => :foo
* a[2] # => 2
* a # => [:foo, "bar", 2]
*
* If +index+ is negative, counts backwards from the end of +self+:
* If +offset+ is negative, counts backwards from the end of +self+:
*
* a = [:foo, 'bar', 2]
* a[-1] # => 2
* a[-2] # => "bar"
*
* If +index+ is out of range, returns +nil+.
*
* When two Integer arguments +start+ and +length+ are given,
* returns a new array of size +length+ containing successive elements beginning at offset +start+:
* When two Integer arguments +offset+ and +size+ are given,
* returns a new array of size +size+ containing successive elements beginning at offset +offset+:
*
* a = [:foo, 'bar', 2]
* a[0, 2] # => [:foo, "bar"]
* a[1, 2] # => ["bar", 2]
*
* If <tt>start + length</tt> is greater than <tt>self.length</tt>,
* returns all elements from offset +start+ to the end:
* If <tt>offset + size</tt> is greater than <tt>self.size</tt>,
* returns all elements from offset +offset+ to the end:
*
* a = [:foo, 'bar', 2]
* a[0, 4] # => [:foo, "bar", 2]
* a[1, 3] # => ["bar", 2]
* a[2, 2] # => [2]
*
* If <tt>start == self.size</tt> and <tt>length >= 0</tt>,
* If <tt>offset == self.size</tt> and <tt>size >= 0</tt>,
* returns a new empty array.
*
* If +length+ is negative, returns +nil+.
* If +size+ is negative, returns +nil+.
*
* When a single Range argument +range+ is given,
* treats <tt>range.min</tt> as +start+ above
* and <tt>range.size</tt> as +length+ above:
* treats <tt>range.min</tt> as +offset+ above
* and <tt>range.size</tt> as +size+ above:
*
* a = [:foo, 'bar', 2]
* a[0..1] # => [:foo, "bar"]
Expand Down
12 changes: 10 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,17 @@ AC_ARG_WITH(baseruby,
],
[
AC_PATH_PROG([BASERUBY], [ruby], [false])
HAVE_BASERUBY=
])
AS_IF([test "$HAVE_BASERUBY" != no], [
RUBYOPT=- $BASERUBY --disable=gems "${tooldir}/missing-baseruby.bat" --verbose || HAVE_BASERUBY=no
AS_IF([test "$HAVE_BASERUBY" = no], [
# --without-baseruby
], [error=`RUBYOPT=- $BASERUBY --disable=gems "${tooldir}/missing-baseruby.bat" --verbose 2>&1`], [
HAVE_BASERUBY=yes
], [test "$HAVE_BASERUBY" = ""], [ # no --with-baseruby option
AC_MSG_WARN($error) # just warn and continue
HAVE_BASERUBY=no
], [ # the ruby given by --with-baseruby is too old
AC_MSG_ERROR($error) # bail out
])
AS_IF([test "${HAVE_BASERUBY:=no}" != no], [
AS_CASE(["$build_os"], [mingw*], [
Expand Down
24 changes: 12 additions & 12 deletions doc/string/aref.rdoc
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
Returns the substring of +self+ specified by the arguments.

<b>Form <tt>self[index]</tt></b>
<b>Form <tt>self[offset]</tt></b>

With non-negative integer argument +index+ given,
returns the 1-character substring found in self at character offset index:
With non-negative integer argument +offset+ given,
returns the 1-character substring found in self at character offset +offset+:

'hello'[0] # => "h"
'hello'[4] # => "o"
'hello'[5] # => nil
'こんにちは'[4] # => "は"

With negative integer argument +index+ given,
With negative integer argument +offset+ given,
counts backward from the end of +self+:

'hello'[-1] # => "o"
'hello'[-5] # => "h"
'hello'[-6] # => nil

<b>Form <tt>self[start, length]</tt></b>
<b>Form <tt>self[offset, size]</tt></b>

With integer arguments +start+ and +length+ given,
returns a substring of size +length+ characters (as available)
beginning at character offset specified by +start+.
With integer arguments +offset+ and +size+ given,
returns a substring of size +size+ characters (as available)
beginning at character offset specified by +offset+.

If argument +start+ is non-negative,
the offset is +start+:
If argument +offset+ is non-negative,
the offset is +offset+:

'hello'[0, 1] # => "h"
'hello'[0, 5] # => "hello"
Expand All @@ -33,15 +33,15 @@ the offset is +start+:
'hello'[2, 0] # => ""
'hello'[2, -1] # => nil

If argument +start+ is negative,
If argument +offset+ is negative,
counts backward from the end of +self+:

'hello'[-1, 1] # => "o"
'hello'[-5, 5] # => "hello"
'hello'[-1, 0] # => ""
'hello'[-6, 5] # => nil

Special case: if +start+ equals the length of +self+,
Special case: if +offset+ equals the size of +self+,
returns a new empty string:

'hello'[5, 3] # => ""
Expand Down
4 changes: 2 additions & 2 deletions internal/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ PRINTF_ARGS(void rb_warn_deprecated_to_remove(const char *removal, const char *f
PRINTF_ARGS(void rb_warn_reserved_name(const char *removal, const char *fmt, ...), 2, 3);
#if RUBY_DEBUG
# include "ruby/version.h"
# define RUBY_VERSION_SINCE(major, minor) (RUBY_API_VERSION_CODE >= (major * 10000) + (minor) * 100)
# define RUBY_VERSION_BEFORE(major, minor) (RUBY_API_VERSION_CODE < (major * 10000) + (minor) * 100)
# define RUBY_VERSION_SINCE(major, minor) (RUBY_API_VERSION_CODE >= (major) * 10000 + (minor) * 100)
# define RUBY_VERSION_BEFORE(major, minor) (RUBY_API_VERSION_CODE < (major) * 10000 + (minor) * 100)
# if defined(RBIMPL_WARNING_PRAGMA0)
# define RBIMPL_TODO0(x) RBIMPL_WARNING_PRAGMA0(message(x))
# elif RBIMPL_COMPILER_IS(MSVC)
Expand Down
10 changes: 10 additions & 0 deletions lib/bundled_gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ def self.warning?(name, specs: nil)

return if specs.include?(name)

# Don't warn if a hyphenated gem provides this feature
# (e.g., benchmark-ips provides benchmark/ips, not the benchmark gem)
if subfeature
feature_parts = feature.split("/")
if feature_parts.size >= 2
hyphenated_gem = "#{feature_parts[0]}-#{feature_parts[1]}"
return if specs.include?(hyphenated_gem)
end
end

return if WARNED[name]
WARNED[name] = true

Expand Down
17 changes: 8 additions & 9 deletions re.c
Original file line number Diff line number Diff line change
Expand Up @@ -2213,12 +2213,12 @@ match_ary_aref(VALUE match, VALUE idx, VALUE result)

/*
* call-seq:
* matchdata[index] -> string or nil
* matchdata[start, length] -> array
* matchdata[range] -> array
* matchdata[name] -> string or nil
* self[offset] -> string or nil
* self[offset, size] -> array
* self[range] -> array
* self[name] -> string or nil
*
* When arguments +index+, +start and +length+, or +range+ are given,
* When arguments +offset+, +offset+ and +size+, or +range+ are given,
* returns match and captures in the style of Array#[]:
*
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
Expand Down Expand Up @@ -3663,12 +3663,11 @@ reg_match_pos(VALUE re, VALUE *strp, long pos, VALUE* set_match)

/*
* call-seq:
* regexp =~ string -> integer or nil
* self =~ other -> integer or nil
*
* Returns the integer index (in characters) of the first match
* for +self+ and +string+, or +nil+ if none;
* also sets the
* {rdoc-ref:Regexp global variables}[rdoc-ref:Regexp@Global+Variables]:
* for +self+ and +other+, or +nil+ if none;
* updates {Regexp-related global variables}[rdoc-ref:Regexp@Global+Variables].
*
* /at/ =~ 'input data' # => 7
* $~ # => #<MatchData "at">
Expand Down
21 changes: 15 additions & 6 deletions spec/ruby/library/socket/tcpsocket/shared/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,23 @@
end

it "connects to a server when passed local_host and local_port arguments" do
server = TCPServer.new(SocketSpecs.hostname, 0)
retries = 0
max_retries = 3

begin
available_port = server.addr[1]
ensure
server.close
retries += 1
server = TCPServer.new(SocketSpecs.hostname, 0)
begin
available_port = server.addr[1]
ensure
server.close
end
@socket = TCPSocket.send(@method, @hostname, @server.port,
@hostname, available_port)
rescue Errno::EADDRINUSE
raise if retries >= max_retries
retry
end
@socket = TCPSocket.send(@method, @hostname, @server.port,
@hostname, available_port)
@socket.should be_an_instance_of(TCPSocket)
end

Expand Down
35 changes: 19 additions & 16 deletions string.c
Original file line number Diff line number Diff line change
Expand Up @@ -5011,12 +5011,15 @@ rb_str_byterindex_m(int argc, VALUE *argv, VALUE str)

/*
* call-seq:
* self =~ object -> integer or nil
* self =~ other -> integer or nil
*
* When +object+ is a Regexp, returns the index of the first substring in +self+
* matched by +object+,
* or +nil+ if no match is found;
* updates {Regexp-related global variables}[rdoc-ref:Regexp@Global+Variables]:
* When +other+ is a Regexp:
*
* - Returns the integer index (in characters) of the first match
* for +self+ and +other+, or +nil+ if none;
* - Updates {Regexp-related global variables}[rdoc-ref:Regexp@Global+Variables].
*
* Examples:
*
* 'foo' =~ /f/ # => 0
* $~ # => #<MatchData "f">
Expand All @@ -5034,8 +5037,8 @@ rb_str_byterindex_m(int argc, VALUE *argv, VALUE str)
* /(?<number>\d+)/ =~ 'no. 9' # => 4
* number # => "9" # Assigned.
*
* If +object+ is not a Regexp, returns the value
* returned by <tt>object =~ self</tt>.
* When +other+ is not a Regexp, returns the value
* returned by <tt>other =~ self</tt>.
*
* Related: see {Querying}[rdoc-ref:String@Querying].
*/
Expand Down Expand Up @@ -5713,8 +5716,8 @@ rb_str_aref(VALUE str, VALUE indx)

/*
* call-seq:
* self[index] -> new_string or nil
* self[start, length] -> new_string or nil
* self[offset] -> new_string or nil
* self[offset, size] -> new_string or nil
* self[range] -> new_string or nil
* self[regexp, capture = 0] -> new_string or nil
* self[substring] -> new_string or nil
Expand Down Expand Up @@ -12445,9 +12448,9 @@ sym_casecmp_p(VALUE sym, VALUE other)

/*
* call-seq:
* symbol =~ object -> integer or nil
* self =~ other -> integer or nil
*
* Equivalent to <tt>symbol.to_s =~ object</tt>,
* Equivalent to <tt>self.to_s =~ other</tt>,
* including possible updates to global variables;
* see String#=~.
*
Expand Down Expand Up @@ -12493,11 +12496,11 @@ sym_match_m_p(int argc, VALUE *argv, VALUE sym)

/*
* call-seq:
* symbol[index] -> string or nil
* symbol[start, length] -> string or nil
* symbol[range] -> string or nil
* symbol[regexp, capture = 0] -> string or nil
* symbol[substring] -> string or nil
* self[offset] -> string or nil
* self[offset, size] -> string or nil
* self[range] -> string or nil
* self[regexp, capture = 0] -> string or nil
* self[substring] -> string or nil
*
* Equivalent to <tt>symbol.to_s[]</tt>; see String#[].
*
Expand Down
4 changes: 0 additions & 4 deletions test/ruby/test_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1260,8 +1260,6 @@ def test_fluent_dot
end

def test_fluent_and
omit if /\+PRISM\b/ =~ RUBY_DESCRIPTION

assert_valid_syntax("a\n" "&& foo")
assert_valid_syntax("a\n" "and foo")

Expand All @@ -1285,8 +1283,6 @@ def test_fluent_and
end

def test_fluent_or
omit if /\+PRISM\b/ =~ RUBY_DESCRIPTION

assert_valid_syntax("a\n" "|| foo")
assert_valid_syntax("a\n" "or foo")

Expand Down
Loading