Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4a4485a
Enhanced RDoc for String#index (#5759)
BurdetteLamar Apr 4, 2022
a19b2d5
ruby_gc_set_params: update malloc_limit when env is set
Jan 17, 2022
18044f4
[ruby/psych] Improve libyaml source downloading error messages
XrXr Apr 4, 2022
1ac839d
Apply timescale configuration for tests of Regexp.timeout
mame Apr 5, 2022
839577d
Removed mswin patch for zlib-1.2.11
hsbt Apr 5, 2022
5e7ebc7
Ignore yaml source
hsbt Apr 5, 2022
752c3da
Unflag a splatted flagged hash if the method doesn't use ruby2_keywords
jeremyevans Mar 11, 2022
4f25207
Use latest RSpec to get rspec-mocks ruby2_keywords fix
eregon Mar 21, 2022
d3f659d
Add NEWS entry for Bug #18625 to help adding ruby2_keywords in the mi…
eregon Apr 5, 2022
5730059
Give some tips on how to find the missing ruby2_keywords
eregon Apr 5, 2022
d9c6f8d
Try to fix NoMethodError on slow environments
znz Apr 5, 2022
97ce030
Load fake.rb at `BTESTRUBY`
nobu Apr 1, 2022
3bb70a6
Fix using anonymous block in method accepting explicit keywords
jeremyevans Apr 4, 2022
2304cfa
Document MakeMakefile#append_cflags
XrXr Apr 4, 2022
5571ca3
* 2022-04-06 [ci skip]
matzbot Apr 5, 2022
8ee4a82
RubyVM.stat constant cache metrics (#5766)
kddnewton Apr 5, 2022
b3f1b3c
[rubygems/rubygems] Enable mfa on specific keys during gem signin
aellispierce Jan 24, 2022
4ae3b78
[rubygems/rubygems] Correct mfa level name
aellispierce Jan 24, 2022
7bb6449
[rubygems/rubygems] Make mfa the default
aellispierce Jan 24, 2022
8650811
[rubygems/rubygems] Fix lint
aellispierce Jan 24, 2022
925d73b
[rubygems/rubygems] Make changes <2.6 compatible
aellispierce Jan 24, 2022
ec09b2d
[rubygems/rubygems] Remove whitespace
aellispierce Jan 24, 2022
7508370
[rubygems/rubygems] Update endpoint
aellispierce Feb 22, 2022
bb3ecdb
[rubygems/rubygems] Accomodate gem hosts without profile/me endpoint
aellispierce Feb 24, 2022
b75b67f
[rubygems/rubygems] Use YAML
aellispierce Feb 24, 2022
37a19f7
[rubygems/rubygems] Extract default_host method
aellispierce Mar 8, 2022
c59488a
[rubygems/rubygems] Use `ask_yes_no`
aellispierce Mar 22, 2022
8da0b68
Fix a typo [ci skip]
znz Apr 6, 2022
8197ae3
Bundle RBS 2.3.2 (#5762)
soutaro Apr 6, 2022
1f3448f
Update bundled gems list at 8197ae35f90aa1c260b5782c08827d [ci skip]
matzbot Apr 6, 2022
717b20e
[DOC] Enhanced RDoc for string slices (#5769)
BurdetteLamar Apr 6, 2022
86411f6
* 2022-04-07 [ci skip]
matzbot Apr 6, 2022
c8647df
Merge upstream/master into aw/sync
XrXr Apr 6, 2022
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
35 changes: 34 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,37 @@ Note that each entry is kept to a minimum, see links for details.
* Find pattern is no longer experimental.
[[Feature #18585]]

* Methods taking a rest parameter (like `*args`) and wishing to delegate keyword
arguments through `foo(*args)` must now be marked with `ruby2_keywords`
(if not already the case). In other words, all methods wishing to delegate
keyword arguments through `*args` must now be marked with `ruby2_keywords`,
with no exception. This will make it easier to transition to other ways of
delegation once a library can require Ruby 3+. Previously, the `ruby2_keywords`
flag was kept if the receiving method took `*args`, but this was a bug and an
inconsistency. A good technique to find the potentially-missing `ruby2_keywords`
is to run the test suite, for where it fails find the last method which must
receive keyword arguments, use `puts nil, caller, nil` there, and check each
method/block on the call chain which must delegate keywords is correctly marked
as `ruby2_keywords`. [[Bug #18625]] [[Bug #16466]]

```ruby
def target(**kw)
end

# Accidentally worked without ruby2_keywords in Ruby 2.7-3.1, ruby2_keywords
# needed in 3.2+. Just like (*args, **kwargs) or (...) would be needed on
# both #foo and #bar when migrating away from ruby2_keywords.
ruby2_keywords def bar(*args)
target(*args)
end

ruby2_keywords def foo(*args)
bar(*args)
end

foo(k: 1)
```

## Command line options

## Core classes updates
Expand Down Expand Up @@ -128,7 +159,7 @@ Note: We're only listing outstanding class updates.
* securerandom 0.2.0
* The following bundled gems are updated.
* net-imap 0.2.3
* rbs 2.3.0
* rbs 2.3.2
* typeprof 0.21.2
* debug 1.5.0
* The following default gems are now bundled gems.
Expand Down Expand Up @@ -203,6 +234,7 @@ The following deprecated APIs are removed.
[Feature #15357]: https://bugs.ruby-lang.org/issues/15357
[Bug #15928]: https://bugs.ruby-lang.org/issues/15928
[Feature #16131]: https://bugs.ruby-lang.org/issues/16131
[Bug #16466]: https://bugs.ruby-lang.org/issues/16466
[Feature #16806]: https://bugs.ruby-lang.org/issues/16806
[Bug #16889]: https://bugs.ruby-lang.org/issues/16889
[Bug #16908]: https://bugs.ruby-lang.org/issues/16908
Expand All @@ -217,4 +249,5 @@ The following deprecated APIs are removed.
[Feature #18571]: https://bugs.ruby-lang.org/issues/18571
[Feature #18585]: https://bugs.ruby-lang.org/issues/18585
[Feature #18598]: https://bugs.ruby-lang.org/issues/18598
[Bug #18625]: https://bugs.ruby-lang.org/issues/18625
[Bug #18633]: https://bugs.ruby-lang.org/issues/18633
8 changes: 4 additions & 4 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ $(arch)-fake.rb: $(srcdir)/template/fake.rb.in $(tooldir)/generic_erb.rb version

btest: $(TEST_RUNNABLE)-btest
no-btest: PHONY
yes-btest: fake miniruby$(EXEEXT) PHONY
yes-btest: yes-fake miniruby$(EXEEXT) PHONY
$(ACTIONS_GROUP)
$(Q)$(exec) $(BOOTSTRAPRUBY) "$(srcdir)/bootstraptest/runner.rb" --ruby="$(BTESTRUBY) $(RUN_OPTS)" $(OPTS) $(TESTOPTS) $(BTESTS)
$(ACTIONS_ENDGROUP)
Expand All @@ -777,7 +777,7 @@ yes-btest-ruby: prog PHONY
$(Q)$(exec) $(RUNRUBY) "$(srcdir)/bootstraptest/runner.rb" --ruby="$(PROGRAM) -I$(srcdir)/lib $(RUN_OPTS)" -q $(OPTS) $(TESTOPTS) $(BTESTS)
$(ACTIONS_ENDGROUP)

rtest: fake miniruby$(EXEEXT) PHONY
rtest: yes-fake miniruby$(EXEEXT) PHONY
$(ACTIONS_GROUP)
$(Q)$(exec) $(BOOTSTRAPRUBY) "$(srcdir)/bootstraptest/runner.rb" --ruby="$(BTESTRUBY) $(RUN_OPTS)" --sets=ractor -v
$(ACTIONS_ENDGROUP)
Expand Down Expand Up @@ -1243,7 +1243,7 @@ $(srcdir)/ext/etc/constdefs.h: $(srcdir)/ext/etc/depend

##

run: fake miniruby$(EXEEXT) PHONY
run: yes-fake miniruby$(EXEEXT) PHONY
$(BTESTRUBY) $(RUNOPT0) $(TESTRUN_SCRIPT) $(RUNOPT)

runruby: $(PROGRAM) PHONY
Expand All @@ -1252,7 +1252,7 @@ runruby: $(PROGRAM) PHONY
runirb: $(PROGRAM) PHONY
RUBY_ON_BUG='gdb -x $(srcdir)/.gdbinit -p' $(RUNRUBY) $(RUNOPT0) -r irb -e 'IRB.start("make runirb")' $(RUNOPT)

parse: fake miniruby$(EXEEXT) PHONY
parse: yes-fake miniruby$(EXEEXT) PHONY
$(BTESTRUBY) --dump=parsetree_with_comment,insns $(TESTRUN_SCRIPT)

bisect: PHONY
Expand Down
38 changes: 38 additions & 0 deletions doc/string/index.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Returns the integer index of the first match for the given argument,
or +nil+ if none found;
the search of +self+ is forward, and begins at position +offset+ (in characters).

With string argument +substring+,
returns the index of the first matching substring in +self+:

'foo'.index('f') # => 0
'foo'.index('o') # => 1
'foo'.index('oo') # => 1
'foo'.index('ooo') # => nil
'тест'.index('с') # => 2
'こんにちは'.index('ち') # => 3

With Regexp argument +regexp+, returns the index of the first match in +self+:

'foo'.index(/o./) # => 1
'foo'.index(/.o/) # => 0

With positive integer +offset+, begins the search at position +offset+:

'foo'.index('o', 1) # => 1
'foo'.index('o', 2) # => 2
'foo'.index('o', 3) # => nil
'тест'.index('с', 1) # => 2
'こんにちは'.index('ち', 2) # => 3

With negative integer +offset+, selects the search position by counting backward
from the end of +self+:

'foo'.index('o', -1) # => 2
'foo'.index('o', -2) # => 1
'foo'.index('o', -3) # => 1
'foo'.index('o', -4) # => nil
'foo'.index(/o./, -2) # => 1
'foo'.index(/.o/, -2) # => 1

Related: String#rindex.
138 changes: 138 additions & 0 deletions doc/string/slices.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
== \String Slices

A _slice_ of a string is a substring that is selected by certain criteria.

These instance methods make use of slicing:

- String#[] (also aliased as String#slice) returns a slice copied from +self+.
- String#[]= returns a copy of +self+ with a slice replaced.
- String#slice! returns +self+ with a slice removed.

Each of the above methods takes arguments that determine the slice
to be copied or replaced.

The arguments have several forms.
For string +string+, the forms are:

- <tt>string[index]</tt>.
- <tt>string[start, length]</tt>.
- <tt>string[range]</tt>.
- <tt>string[regexp, capture = 0]</tt>.
- <tt>string[substring]</tt>.

<b><tt>string[index]</tt></b>

When non-negative integer argument +index+ is given,
the slice is the 1-character substring found in +self+ at character offset +index+:

'bar'[0] # => "b"
'bar'[2] # => "r"
'bar'[20] # => nil
'тест'[2] # => "с"
'こんにちは'[4] # => "は"

When negative integer +index+ is given,
the slice begins at the offset given by counting backward from the end of +self+:

'bar'[-3] # => "b"
'bar'[-1] # => "r"
'bar'[-20] # => nil

<b><tt>string[start, length]</tt></b>

When non-negative integer arguments +start+ and +length+ are given,
the slice begins at character offset +start+, if it exists,
and continues for +length+ characters, if available:

'foo'[0, 2] # => "fo"
'тест'[1, 2] # => "ес"
'こんにちは'[2, 2] # => "にち"
# Zero length.
'foo'[2, 0] # => ""
# Length not entirely available.
'foo'[1, 200] # => "oo"
# Start out of range.
'foo'[4, 2] # => nil

Special case: if +start+ is equal to the length of +self+,
the slice is a new empty string:

'foo'[3, 2] # => ""
'foo'[3, 200] # => ""

When negative +start+ and non-negative +length+ are given,
the slice beginning is determined by counting backward from the end of +self+,
and the slice continues for +length+ characters, if available:

'foo'[-2, 2] # => "oo"
'foo'[-2, 200] # => "oo"
# Start out of range.
'foo'[-4, 2] # => nil

When negative +length+ is given, there is no slice:

'foo'[1, -1] # => nil
'foo'[-2, -1] # => nil

<b><tt>string[range]</tt></b>

When Range argument +range+ is given,
creates a substring of +string+ using the indices in +range+.
The slice is then determined as above:

'foo'[0..1] # => "fo"
'foo'[0, 2] # => "fo"

'foo'[2...2] # => ""
'foo'[2, 0] # => ""

'foo'[1..200] # => "oo"
'foo'[1, 200] # => "oo"

'foo'[4..5] # => nil
'foo'[4, 2] # => nil

'foo'[-4..-3] # => nil
'foo'[-4, 2] # => nil

'foo'[3..4] # => ""
'foo'[3, 2] # => ""

'foo'[-2..-1] # => "oo"
'foo'[-2, 2] # => "oo"

'foo'[-2..197] # => "oo"
'foo'[-2, 200] # => "oo"

<b><tt>string[regexp, capture = 0]</tt></b>

When the \Regexp argument +regexp+ is given,
and the +capture+ argument is <tt>0</tt>,
the slice is the first matching substring found in +self+:

'foo'[/o/] # => "o"
'foo'[/x/] # => nil
s = 'hello there'
s[/[aeiou](.)\1/] # => "ell"
s[/[aeiou](.)\1/, 0] # => "ell"

If argument +capture+ is given and not <tt>0</tt>,
it should be either an capture group index (integer)
or a capture group name (string or symbol);
the slice is the specified capture (see Regexp@Capturing):

s = 'hello there'
s[/[aeiou](.)\1/, 1] # => "l"
s[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, "non_vowel"] # => "l"
s[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, :vowel] # => "e"

If an invalid capture group index is given, there is no slice.
If an invalid capture group name is given, +IndexError+ is raised.

<b><tt>string[substring]</tt></b>

When the single \String argument +substring+ is given,
returns the substring from +self+ if found, otherwise +nil+:

'foo'['oo'] # => "oo"
'foo'['xx'] # => nil
1 change: 1 addition & 0 deletions ext/psych/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/yaml-[0-9]*.*.*
14 changes: 10 additions & 4 deletions ext/psych/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@
# search the latest libyaml source under $srcdir
yaml_source = Dir.glob("#{$srcdir}/yaml{,-*}/").max_by {|n| File.basename(n).scan(/\d+/).map(&:to_i)}
unless yaml_source
require_relative '../../tool/extlibs.rb'
extlibs = ExtLibs.new(cache_dir: File.expand_path("../../tmp/download_cache", $srcdir))
unless extlibs.process_under($srcdir)
raise "failed to download libyaml source"
download_failure = "failed to download libyaml source"
begin
require_relative '../../tool/extlibs.rb'
extlibs = ExtLibs.new(cache_dir: File.expand_path("../../tmp/download_cache", $srcdir))
unless extlibs.process_under($srcdir)
raise download_failure
end
rescue
# Implicitly captures Exception#cause. Newer rubies show it in the backtrace.
raise download_failure
end
yaml_source, = Dir.glob("#{$srcdir}/yaml-*/")
raise "libyaml not found" unless yaml_source
Expand Down
95 changes: 0 additions & 95 deletions ext/zlib/win32/zlib-1.2.11-mswin.patch

This file was deleted.

Loading