Skip to content

Commit 25bc260

Browse files
authored
Merge pull request #2776 from ksss/ruby-400
2 parents f50c270 + f5ebed1 commit 25bc260

30 files changed

+557
-377
lines changed

.github/workflows/bundle-update.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Set up Ruby
1717
uses: ruby/setup-ruby@v1
1818
with:
19-
ruby-version: '4.0.0-preview3'
19+
ruby-version: '4.0'
2020

2121
- name: Set up git
2222
run: |

.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@v6
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@v6
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"
@@ -74,7 +74,7 @@ jobs:
7474
strategy:
7575
fail-fast: false
7676
matrix:
77-
ruby: ['4.0.0-preview3', head]
77+
ruby: ['4.0', head]
7878
steps:
7979
- uses: actions/checkout@v6
8080
- name: Install dependencies
@@ -100,4 +100,3 @@ jobs:
100100
run: |
101101
bin/setup
102102
- run: bundle exec rake clean compile_c99
103-

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
@@ -277,15 +277,16 @@ class Complex < Numeric
277277

278278
# <!--
279279
# rdoc-file=complex.c
280-
# - complex <=> object -> -1, 0, 1, or nil
280+
# - self <=> other -> -1, 0, 1, or nil
281281
# -->
282+
# Compares `self` and `other`.
283+
#
282284
# Returns:
283285
#
284-
# * `self.real <=> object.real` if both of the following are true:
286+
# * `self.real <=> other.real` if both of the following are true:
285287
#
286288
# * `self.imag == 0`.
287-
# * `object.imag == 0`. # Always true if object is numeric but not
288-
# complex.
289+
# * `other.imag == 0` (always true if `other` is numeric but not complex).
289290
#
290291
# * `nil` otherwise.
291292
#
@@ -298,6 +299,9 @@ class Complex < Numeric
298299
# Complex.rect(1) <=> Complex.rect(1, 1) # => nil # object.imag not zero.
299300
# Complex.rect(1) <=> 'Foo' # => nil # object.imag not defined.
300301
#
302+
# Class Complex includes module Comparable, each of whose methods uses
303+
# Complex#<=> for comparison.
304+
#
301305
def <=>: (untyped) -> Integer?
302306

303307
# <!--

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
# <!--

0 commit comments

Comments
 (0)