Skip to content

Commit e9990ed

Browse files
authored
Merge pull request ruby#145 from Shopify/merge_upstream
Merge upstream Ruby commits
2 parents 68d31e6 + bc6ae6f commit e9990ed

File tree

165 files changed

+1921
-865
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+1921
-865
lines changed

NEWS.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,12 @@ Excluding feature bug fixes.
191191
Just by `Kernel#p`, you can investigate where an object was created.
192192
Note that just requiring this file brings a large performance overhead.
193193
This is only for debugging purpose. Do not use this in production.
194-
[Feature #17762]
194+
[[Feature #17762]]
195195

196-
[Bug #4443]: https://bugs.ruby-lang.org/issues/4443
196+
* Now exceptions raised in finalizers will be printed to `STDERR`, unless
197+
`$VERBOSE` is `nil`. [[Feature #17798]]
198+
199+
[Bug #4443]: https://bugs.ruby-lang.org/issues/4443
197200
[Feature #12194]: https://bugs.ruby-lang.org/issues/12194
198201
[Feature #14256]: https://bugs.ruby-lang.org/issues/14256
199202
[Feature #15198]: https://bugs.ruby-lang.org/issues/15198
@@ -203,15 +206,16 @@ Excluding feature bug fixes.
203206
[Feature #17312]: https://bugs.ruby-lang.org/issues/17312
204207
[Feature #17327]: https://bugs.ruby-lang.org/issues/17327
205208
[Feature #17411]: https://bugs.ruby-lang.org/issues/17411
206-
[Bug #17423]: https://bugs.ruby-lang.org/issues/17423
209+
[Bug #17423]: https://bugs.ruby-lang.org/issues/17423
207210
[Feature #17479]: https://bugs.ruby-lang.org/issues/17479
208211
[Feature #17490]: https://bugs.ruby-lang.org/issues/17490
209212
[Feature #17724]: https://bugs.ruby-lang.org/issues/17724
210213
[Feature #17744]: https://bugs.ruby-lang.org/issues/17744
211214
[Feature #17762]: https://bugs.ruby-lang.org/issues/17762
212-
[Bug #18003]: https://bugs.ruby-lang.org/issues/18003
215+
[Feature #17798]: https://bugs.ruby-lang.org/issues/17798
216+
[Bug #18003]: https://bugs.ruby-lang.org/issues/18003
213217
[Feature #17370]: https://bugs.ruby-lang.org/issues/17370
214218
[Feature #17470]: https://bugs.ruby-lang.org/issues/17470
215219
[Feature #17853]: https://bugs.ruby-lang.org/issues/17853
216-
[Bug #17827]: https://bugs.ruby-lang.org/issues/17827
220+
[Bug #17827]: https://bugs.ruby-lang.org/issues/17827
217221
[Feature #18015]: https://bugs.ruby-lang.org/issues/18015

array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8384,7 +8384,7 @@ Init_Array(void)
83848384
rb_define_method(rb_cArray, "each_index", rb_ary_each_index, 0);
83858385
rb_define_method(rb_cArray, "reverse_each", rb_ary_reverse_each, 0);
83868386
rb_define_method(rb_cArray, "length", rb_ary_length, 0);
8387-
rb_define_alias(rb_cArray, "size", "length");
8387+
rb_define_method(rb_cArray, "size", rb_ary_length, 0);
83888388
rb_define_method(rb_cArray, "empty?", rb_ary_empty_p, 0);
83898389
rb_define_method(rb_cArray, "find_index", rb_ary_index, -1);
83908390
rb_define_method(rb_cArray, "index", rb_ary_index, -1);

common.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ gnumake_recursive =
1919
enable_shared = $(ENABLE_SHARED:no=)
2020

2121
UNICODE_VERSION = 13.0.0
22-
UNICODE_EMOJI_VERSION = 13.0
22+
UNICODE_EMOJI_VERSION = 13.1
2323
UNICODE_BETA = NO
2424

2525
### set the following environment variable or uncomment the line if

defs/id.def

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ firstline, predefined = __LINE__+1, %[\
2525
send
2626
__send__
2727
__attached__
28+
__recursive_key__
2829
initialize
2930
initialize_copy
3031
initialize_clone
@@ -138,6 +139,21 @@ class KeywordError < RuntimeError
138139
end
139140
end
140141

142+
def id2varname(token, prefix = nil)
143+
if /#/ =~ token
144+
token = "_#{token.gsub(/\W+/, '_')}"
145+
else
146+
token = token.sub(/\?/, 'P')
147+
token = prefix + token if prefix
148+
token.sub!(/\A[a-z]/) {$&.upcase}
149+
token.sub!(/\A\$/, "_G_")
150+
token.sub!(/\A@@/, "_C_")
151+
token.sub!(/\A@/, "_I_")
152+
token.gsub!(/\W+/, "")
153+
end
154+
token
155+
end
156+
141157
predefined_ids = {}
142158
preserved_ids = []
143159
local_ids = []
@@ -153,16 +169,7 @@ predefined.split(/^/).each_with_index do |line, num|
153169
line.sub!(/\s+#.*/, '')
154170
name, token = line.split
155171
next unless name
156-
token ||= name
157-
if /#/ =~ token
158-
token = "_#{token.gsub(/\W+/, '_')}"
159-
else
160-
token = token.sub(/\?/, 'P').sub(/\A[a-z]/) {$&.upcase}
161-
token.sub!(/\A\$/, "_G_")
162-
token.sub!(/\A@@/, "_C_")
163-
token.sub!(/\A@/, "_I_")
164-
token.gsub!(/\W+/, "")
165-
end
172+
token = id2varname(token || name)
166173
if name == '-'
167174
preserved_ids << token
168175
next

doc/optparse/argument_converters.rdoc

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Executions:
216216

217217
File +decimal_numeric.rb+
218218
defines an option whose argument is to be converted to an \Integer object.
219-
The argument is converted by method {Kernel#Integer
219+
The argument is converted by method Kernel#Integer
220220

221221
:include: ruby/decimal_numeric.rb
222222

@@ -345,8 +345,14 @@ Executions:
345345
=== Custom Argument Converters
346346

347347
You can create custom argument converters.
348-
To create a custom converter, call OptionParser#accept with a class argument,
349-
along with a block that converts the argument and returns the converted value.
348+
To create a custom converter, call OptionParser#accept with:
349+
350+
- An identifier, which may be any object.
351+
- An optional match pattern, which defaults to <tt>/.*/m</tt>.
352+
- A block that accepts the argument and returns the converted value.
353+
354+
This custom converter accepts any argument and converts it,
355+
if possible, to a \Complex object.
350356

351357
:include: ruby/custom_converter.rb
352358

@@ -360,3 +366,15 @@ Executions:
360366
[(1+2i), Complex]
361367
$ ruby custom_converter.rb --complex 0.3-0.5i
362368
[(0.3-0.5i), Complex]
369+
370+
This custom converter accepts any 1-word argument
371+
and capitalizes it, if possible.
372+
373+
:include: ruby/match_converter.rb
374+
375+
Executions:
376+
377+
$ ruby match_converter.rb --capitalize foo
378+
["Foo", String]
379+
$ ruby match_converter.rb --capitalize "foo bar"
380+
match_converter.rb:9:in `<main>': invalid argument: --capitalize foo bar (OptionParser::InvalidArgument)

doc/optparse/creates_option.rdoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Creates an option from the given parameters +params+.
2-
See {Parameters for New Options}[./option_params_rdoc.html].
2+
See {Parameters for New Options}[./doc/optparse/option_params_rdoc.html].
33

44
The block, if given, is the handler for the created option.
55
When the option is encountered during command-line parsing,

doc/optparse/option_params.rdoc

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ Contents:
4343
- {Handler Blocks}[#label-Handler+Blocks]
4444
- {Handler Procs}[#label-Handler+Procs]
4545
- {Handler Methods}[#label-Handler+Methods]
46-
- {Terminators}[#label-Terminators]
4746

4847
=== Option Names
4948

@@ -319,7 +318,7 @@ You can specify argument values in either of two ways:
319318
===== Explicit Values in Array
320319

321320
You can specify explicit argument values in an array of strings.
322-
The argument value must be one of those strings.
321+
The argument value must be one of those strings, or an unambiguous abbreviation.
323322

324323
File +explicit_array_values.rb+ defines options with explicit argument values.
325324

@@ -335,17 +334,21 @@ Executions:
335334
explicit_array_values.rb:9:in `<main>': missing argument: -x (OptionParser::MissingArgument)
336335
$ ruby explicit_array_values.rb -x foo
337336
["-x", "foo"]
337+
$ ruby explicit_array_values.rb -x f
338+
["-x", "foo"]
338339
$ ruby explicit_array_values.rb -x bar
339340
["-x", "bar"]
341+
$ ruby explicit_array_values.rb -y ba
342+
explicit_array_values.rb:9:in `<main>': ambiguous argument: -y ba (OptionParser::AmbiguousArgument)
340343
$ ruby explicit_array_values.rb -x baz
341344
explicit_array_values.rb:9:in `<main>': invalid argument: -x baz (OptionParser::InvalidArgument)
342345

343346

344347
===== Explicit Values in Hash
345348

346349
You can specify explicit argument values in a hash with string keys.
347-
The value passed must be one of those keys,
348-
and the value yielded will be the value for that key.
350+
The value passed must be one of those keys, or an unambiguous abbreviation;
351+
the value yielded will be the value for that key.
349352

350353
File +explicit_hash_values.rb+ defines options with explicit argument values.
351354

@@ -361,6 +364,8 @@ Executions:
361364
explicit_hash_values.rb:9:in `<main>': missing argument: -x (OptionParser::MissingArgument)
362365
$ ruby explicit_hash_values.rb -x foo
363366
["-x", 0]
367+
$ ruby explicit_hash_values.rb -x f
368+
["-x", 0]
364369
$ ruby explicit_hash_values.rb -x bar
365370
["-x", 1]
366371
$ ruby explicit_hash_values.rb -x baz
@@ -371,6 +376,8 @@ Executions:
371376
["-y", 2]
372377
$ ruby explicit_hash_values.rb -y bat
373378
["-y", 3]
379+
$ ruby explicit_hash_values.rb -y ba
380+
explicit_hash_values.rb:9:in `<main>': ambiguous argument: -y ba (OptionParser::AmbiguousArgument)
374381
$ ruby explicit_hash_values.rb -y bam
375382
["-y", nil]
376383

@@ -500,22 +507,3 @@ Executions:
500507
["Handler method for -xxx called with value:", true]
501508
$ ruby method.rb --yyy FOO
502509
["Handler method for -yyy called with value:", "FOO"]
503-
504-
=== Terminators
505-
506-
And finally, the terminator parameter <tt>--</tt> tells the options parser
507-
to ignore any options farther to the right.
508-
This can be useful if there are options not meant for the current program.
509-
510-
File +terminator.rb+ defines one option <tt>--my_option</tt>.
511-
512-
:include: ruby/terminator.rb
513-
514-
The first execution fails because <tt>--nosuch</tt> is not a defined option;
515-
the second succeeds because <tt>--</tt> causes that option to be ignored:
516-
517-
$ ruby terminator.rb --my_option FOO --other_option BAR
518-
["FOO", String]
519-
terminator.rb:6:in `<main>': invalid option: --other_option (OptionParser::InvalidOption)
520-
$ ruby terminator.rb --my_option FOO -- --other_option BAR
521-
["FOO", String]

doc/optparse/ruby/basic.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Require the OptionParser code.
2+
require 'optparse'
3+
# Create an OptionParser object.
4+
parser = OptionParser.new
5+
# Define one or more options.
6+
parser.on('-x', 'Whether to X') do |value|
7+
p ['x', value]
8+
end
9+
parser.on('-y', 'Whether to Y') do |value|
10+
p ['y', value]
11+
end
12+
parser.on('-z', 'Whether to Z') do |value|
13+
p ['z', value]
14+
end
15+
# Parse the command line and return pared-down ARGV.
16+
p parser.parse!
17+

doc/optparse/ruby/help.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require 'optparse'
2+
parser = OptionParser.new
3+
parser.on(
4+
'-x', '--xxx',
5+
'Adipiscing elit. Aenean commodo ligula eget.',
6+
'Aenean massa. Cum sociis natoque penatibus',
7+
)
8+
parser.on(
9+
'-y', '--yyy YYY',
10+
'Lorem ipsum dolor sit amet, consectetuer.'
11+
)
12+
parser.on(
13+
'-z', '--zzz [ZZZ]',
14+
'Et magnis dis parturient montes, nascetur',
15+
'ridiculus mus. Donec quam felis, ultricies',
16+
'nec, pellentesque eu, pretium quis, sem.',
17+
)
18+
parser.parse!

doc/optparse/ruby/help_banner.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'optparse'
2+
parser = OptionParser.new
3+
parser.banner = "Usage: ruby help_banner.rb"
4+
parser.parse!
5+
6+
7+

0 commit comments

Comments
 (0)