Skip to content

Commit 51c9f36

Browse files
authored
Merge pull request #2778 from ksss/backport-ruby-400
[Backport] Update ruby to 4.0
2 parents d95a129 + a716372 commit 51c9f36

29 files changed

+556
-376
lines changed

.github/workflows/c-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- uses: actions/checkout@v4
1313
- uses: ruby/setup-ruby@v1
1414
with:
15-
ruby-version: "4.0.0-preview3"
15+
ruby-version: "4.0"
1616
bundler-cache: none
1717
- name: Set working directory as safe
1818
run: git config --global --add safe.directory $(pwd)

.github/workflows/comments.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ on:
1010
jobs:
1111
comments:
1212
runs-on: "ubuntu-latest"
13-
env:
14-
RUBY_COMMIT: v4.0.0-preview3
13+
# env:
14+
# RUBY_COMMIT: v4.0.0-preview2
1515
steps:
1616
- uses: actions/checkout@v4
1717
- uses: ruby/setup-ruby@v1
1818
with:
19-
ruby-version: "4.0.0-preview3"
19+
ruby-version: "4.0.0"
2020
bundler: none
2121
- name: Install dependencies
2222
run: |

.github/workflows/ruby.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
ruby: ['3.2', '3.3', '3.4', '4.0.0-preview3', head]
16+
ruby: ['3.2', '3.3', '3.4', '4.0', head]
1717
rubyopt: [""]
1818
job:
1919
- test
2020
include:
2121
- ruby: head
2222
job: stdlib_test rubocop
23-
- ruby: "4.0.0-preview3"
23+
- ruby: "4.0"
2424
job: stdlib_test
25-
- ruby: "4.0.0-preview3"
25+
- ruby: "4.0"
2626
job: test
2727
rubyopt: "--enable-frozen-string-literal"
28-
- ruby: "4.0.0-preview3"
28+
- ruby: "4.0"
2929
job: stdlib_test
3030
rubyopt: "--enable-frozen-string-literal"
31-
- ruby: "4.0.0-preview3"
31+
- ruby: "4.0"
3232
job: rubocop validate test_doc build test_generate_stdlib raap
33-
- ruby: "4.0.0-preview3"
33+
- ruby: "4.0"
3434
job: typecheck_test
3535
env:
3636
RANDOMIZE_STDLIB_TEST_ORDER: "true"
@@ -94,7 +94,7 @@ jobs:
9494
strategy:
9595
fail-fast: false
9696
matrix:
97-
ruby: ['4.0.0-preview3', head]
97+
ruby: ['4.0', head]
9898
steps:
9999
- uses: actions/checkout@v4
100100
- name: Install dependencies
@@ -116,4 +116,3 @@ jobs:
116116
run: |
117117
bin/setup
118118
- run: bundle exec rake clean compile_c99
119-

bin/generate_docs.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
set -ex
44

55
if [ -z ${RUBY_COMMIT} ]; then
6-
RUBY_COMMIT=v`ruby -e 'puts RUBY_VERSION.gsub(".", "_")'`
6+
RUBY_COMMIT=v`ruby -e '
7+
case
8+
when RUBY_VERSION >= "4.0.0"
9+
puts RUBY_VERSION
10+
else
11+
puts RUBY_VERSION.gsub(".", "_")
12+
end
13+
'`
714
fi
815

916
if [ -z ${RBS_RDOC_BASE_DIR} ]; then

core/array.rbs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,14 +2029,12 @@ class Array[unchecked out Elem] < Object
20292029
# With a block given, calls the block with successive elements of the array;
20302030
# returns the first element for which the block returns a truthy value:
20312031
#
2032-
# (0..9).find {|element| element > 2} # => 3
2032+
# [1, 3, 5].find {|element| element > 2} # => 3
20332033
#
20342034
# If no such element is found, calls `if_none_proc` and returns its return
20352035
# value.
20362036
#
2037-
# (0..9).find(proc {false}) {|element| element > 12} # => false
2038-
# {foo: 0, bar: 1, baz: 2}.find {|key, value| key.start_with?('b') } # => [:bar, 1]
2039-
# {foo: 0, bar: 1, baz: 2}.find(proc {[]}) {|key, value| key.start_with?('c') } # => []
2037+
# [1, 3, 5].find(proc {-1}) {|element| element > 12} # => -1
20402038
#
20412039
# With no block given, returns an Enumerator.
20422040
#
@@ -3022,17 +3020,15 @@ class Array[unchecked out Elem] < Object
30223020
# Returns the last element for which the block returns a truthy value.
30233021
#
30243022
# With a block given, calls the block with successive elements of the array in
3025-
# reverse order; returns the last element for which the block returns a truthy
3023+
# reverse order; returns the first element for which the block returns a truthy
30263024
# value:
30273025
#
3028-
# (0..9).rfind {|element| element < 5} # => 4
3026+
# [1, 2, 3, 4, 5, 6].rfind {|element| element < 5} # => 4
30293027
#
30303028
# If no such element is found, calls `if_none_proc` and returns its return
30313029
# value.
30323030
#
3033-
# (0..9).rfind(proc {false}) {|element| element < -2} # => false
3034-
# {foo: 0, bar: 1, baz: 2}.rfind {|key, value| key.start_with?('b') } # => [:baz, 2]
3035-
# {foo: 0, bar: 1, baz: 2}.rfind(proc {[]}) {|key, value| key.start_with?('c') } # => []
3031+
# [1, 2, 3, 4].rfind(proc {0}) {|element| element < -2} # => 0
30363032
#
30373033
# With no block given, returns an Enumerator.
30383034
#

core/comparable.rbs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,26 @@
5555
module Comparable : _WithSpaceshipOperator
5656
# <!--
5757
# rdoc-file=compar.c
58-
# - obj < other -> true or false
58+
# - self < other -> true or false
5959
# -->
60-
# Compares two objects based on the receiver's `<=>` method, returning true if
61-
# it returns a value less than 0.
60+
# Returns whether `self` is "less than" `other`; equivalent to `(self <=> other)
61+
# < 0`:
62+
#
63+
# 'foo' < 'foo' # => false
64+
# 'foo' < 'food' # => true
6265
#
6366
def <: (untyped other) -> bool
6467

6568
# <!--
6669
# rdoc-file=compar.c
67-
# - obj <= other -> true or false
70+
# - self <= other -> true or false
6871
# -->
69-
# Compares two objects based on the receiver's `<=>` method, returning true if
70-
# it returns a value less than or equal to 0.
72+
# Returns whether `self` is "less than or equal to" `other`; equivalent to
73+
# `(self <=> other) <= 0`:
74+
#
75+
# 'foo' <= 'foo' # => true
76+
# 'foo' <= 'food' # => true
77+
# 'food' <= 'foo' # => false
7178
#
7279
def <=: (untyped other) -> bool
7380

core/complex.rbs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,16 @@ class Complex < Numeric
279279

280280
# <!--
281281
# rdoc-file=complex.c
282-
# - complex <=> object -> -1, 0, 1, or nil
282+
# - self <=> other -> -1, 0, 1, or nil
283283
# -->
284+
# Compares `self` and `other`.
285+
#
284286
# Returns:
285287
#
286-
# * `self.real <=> object.real` if both of the following are true:
288+
# * `self.real <=> other.real` if both of the following are true:
287289
#
288290
# * `self.imag == 0`.
289-
# * `object.imag == 0`. # Always true if object is numeric but not
290-
# complex.
291+
# * `other.imag == 0` (always true if `other` is numeric but not complex).
291292
#
292293
# * `nil` otherwise.
293294
#
@@ -300,6 +301,9 @@ class Complex < Numeric
300301
# Complex.rect(1) <=> Complex.rect(1, 1) # => nil # object.imag not zero.
301302
# Complex.rect(1) <=> 'Foo' # => nil # object.imag not defined.
302303
#
304+
# Class Complex includes module Comparable, each of whose methods uses
305+
# Complex#<=> for comparison.
306+
#
303307
def <=>: (untyped) -> Integer?
304308

305309
# <!--

core/dir.rbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class Dir
171171
# system's encoding is used:
172172
#
173173
# Dir.new('.').read.encoding # => #<Encoding:UTF-8>
174-
# Dir.new('.', encoding: 'US-ASCII').read.encoding # => #<Encoding:US-ASCII>
174+
# Dir.new('.', encoding: Encoding::US_ASCI).read.encoding # => #<Encoding:US-ASCII>
175175
#
176176
def initialize: (path dir, ?encoding: encoding?) -> void
177177

@@ -704,7 +704,7 @@ class Dir
704704
# system's encoding is used:
705705
#
706706
# Dir.open('.').read.encoding # => #<Encoding:UTF-8>
707-
# Dir.open('.', encoding: 'US-ASCII').read.encoding # => #<Encoding:US-ASCII>
707+
# Dir.open('.', encoding: Encoding::US_ASCII).read.encoding # => #<Encoding:US-ASCII>
708708
#
709709
def self.open: (path dirname, ?encoding: encoding?) -> instance
710710
| [U] (path dirname, ?encoding: encoding?) { (instance) -> U } -> U

core/enumerator.rbs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ class Enumerator[unchecked out Elem, out Return = void] < Object
186186
# }
187187
# traverser.size # => 4
188188
#
189+
# # Finite enumerator with unknown size
190+
# calendar = Enumerator.produce(Date.today, size: nil) {
191+
# it.monday? ? raise(StopIteration) : it + 1
192+
# }
193+
# calendar.size # => nil
194+
#
189195
def self.produce: [T] () { (T? prev) -> T } -> Enumerator[T, bot]
190196
| [T] (T initial) { (T prev) -> T } -> Enumerator[T, bot]
191197

@@ -463,6 +469,25 @@ class Enumerator[unchecked out Elem, out Return = void] < Object
463469
# loop.size # => Float::INFINITY
464470
# (1..100).drop_while.size # => nil
465471
#
472+
# Note that enumerator size might be inaccurate, and should be rather treated as
473+
# a hint. For example, there is no check that the size provided to ::new is
474+
# accurate:
475+
#
476+
# e = Enumerator.new(5) { |y| 2.times { y << it} }
477+
# e.size # => 5
478+
# e.to_a.size # => 2
479+
#
480+
# Another example is an enumerator created by ::produce without a `size`
481+
# argument. Such enumerators return `Infinity` for size, but this is inaccurate
482+
# if the passed block raises StopIteration:
483+
#
484+
# e = Enumerator.produce(1) { it + 1 }
485+
# e.size # => Infinity
486+
#
487+
# e = Enumerator.produce(1) { it > 3 ? raise(StopIteration) : it + 1 }
488+
# e.size # => Infinity
489+
# e.to_a.size # => 4
490+
#
466491
def size: () -> (Integer | Float)?
467492

468493
# <!--

core/fiber.rbs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -393,27 +393,35 @@ class Fiber < Object
393393

394394
# <!--
395395
# rdoc-file=cont.c
396-
# - fiber.raise -> obj
397-
# - fiber.raise(string) -> obj
398-
# - fiber.raise(exception [, string [, array]]) -> obj
396+
# - raise(exception, message = exception.to_s, backtrace = nil, cause: $!)
397+
# - raise(message = nil, cause: $!)
399398
# -->
400399
# Raises an exception in the fiber at the point at which the last `Fiber.yield`
401-
# was called. If the fiber has not been started or has already run to
402-
# completion, raises `FiberError`. If the fiber is yielding, it is resumed. If
403-
# it is transferring, it is transferred into. But if it is resuming, raises
404-
# `FiberError`.
405-
#
406-
# With no arguments, raises a `RuntimeError`. With a single `String` argument,
407-
# raises a `RuntimeError` with the string as a message. Otherwise, the first
408-
# parameter should be the name of an `Exception` class (or an object that
409-
# returns an `Exception` object when sent an `exception` message). The optional
410-
# second parameter sets the message associated with the exception, and the third
411-
# parameter is an array of callback information. Exceptions are caught by the
412-
# `rescue` clause of `begin...end` blocks.
400+
# was called.
401+
#
402+
# f = Fiber.new {
403+
# puts "Before the yield"
404+
# Fiber.yield 1 # -- exception will be raised here
405+
# puts "After the yield"
406+
# }
407+
#
408+
# p f.resume
409+
# f.raise "Gotcha"
410+
#
411+
# Output
412+
#
413+
# Before the first yield
414+
# 1
415+
# t.rb:8:in 'Fiber.yield': Gotcha (RuntimeError)
416+
# from t.rb:8:in 'block in <main>'
417+
#
418+
# If the fiber has not been started or has already run to completion, raises
419+
# `FiberError`. If the fiber is yielding, it is resumed. If it is transferring,
420+
# it is transferred into. But if it is resuming, raises `FiberError`.
413421
#
414422
# Raises `FiberError` if called on a Fiber belonging to another `Thread`.
415423
#
416-
# See Kernel#raise for more information.
424+
# See Kernel#raise for more information on arguments.
417425
#
418426
def raise: (?string msg, ?cause: Exception?) -> untyped
419427
| (_Exception, ?string msg, ?Array[string] | Array[Thread::Backtrace::Location] | nil backtrace, ?cause: Exception?) -> untyped

0 commit comments

Comments
 (0)