Skip to content

Commit 3672a46

Browse files
authored
Merge pull request #3014 from sekito1107/fix/issue-2974
Ruby 3.4 の引用符変更に伴うバックトレース表示例の更新 (#2974)
2 parents c9a3f3b + 01c173a commit 3672a46

24 files changed

Lines changed: 269 additions & 4 deletions

refm/api/src/_builtin/Array

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,14 +2084,22 @@ p [].transpose
20842084

20852085
p [1,2,3].transpose
20862086

2087+
#@since 3.4
2088+
# => -:1:in 'transpose': cannot convert Fixnum into Array (TypeError)
2089+
#@else
20872090
# => -:1:in `transpose': cannot convert Fixnum into Array (TypeError)
2091+
#@end
20882092
# from -:1
20892093

20902094
p [[1,2],
20912095
[3,4,5],
20922096
[6,7]].transpose
2097+
#@since 3.4
2098+
# => -:3:in 'transpose': element size differ (3 should be 2) (IndexError)
2099+
#@else
20932100
# => -:3:in `transpose': element size differ (3 should be 2) (IndexError)
20942101
#@end
2102+
#@end
20952103

20962104
--- uniq -> Array
20972105
--- uniq! -> self | nil

refm/api/src/_builtin/Data

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,18 @@ Point.new に渡した位置引数の数が多い場合(上から2番目)のみ
162162
#@samplecode 例
163163
Point = Data.define(:x, :y)
164164

165+
#@since 3.4
166+
Point.new(1) # => in 'initialize': missing keyword: :y (ArgumentError)
167+
Point.new(1, 2, 3) # => in 'new': wrong number of arguments (given 3, expected 0..2) (ArgumentError)
168+
Point.new(x: 1) # => in 'initialize': missing keyword: :y (ArgumentError)
169+
Point.new(x: 1, y: 2, z: 3) # => in 'initialize': unknown keyword: :z (ArgumentError)
170+
#@else
165171
Point.new(1) # => in `initialize': missing keyword: :y (ArgumentError)
166172
Point.new(1, 2, 3) # => in `new': wrong number of arguments (given 3, expected 0..2) (ArgumentError)
167173
Point.new(x: 1) # => in `initialize': missing keyword: :y (ArgumentError)
168174
Point.new(x: 1, y: 2, z: 3) # => in `initialize': unknown keyword: :z (ArgumentError)
169175
#@end
176+
#@end
170177

171178
下の例のように、initialize メソッドをオーバーライドすることで new のオプション引数を実現できます。
172179

refm/api/src/_builtin/Exception

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@ end
6363

6464
デフォルトでは
6565

66+
#@since 3.4
67+
* "#{sourcefile}:#{sourceline}:in '#{method}'"
68+
(メソッド内の場合)
69+
#@else
6670
* "#{sourcefile}:#{sourceline}:in `#{method}'"
6771
(メソッド内の場合)
72+
#@end
6873
* "#{sourcefile}:#{sourceline}"
6974
(トップレベルの場合)
7075

@@ -81,8 +86,12 @@ rescue => e
8186
p e.backtrace
8287
end
8388

89+
#@since 3.4
90+
#=> ["filename.rb:2:in 'methd'", "filename.rb:6"]
91+
#@else
8492
#=> ["filename.rb:2:in `methd'", "filename.rb:6"]
8593
#@end
94+
#@end
8695

8796
#@since 2.1.0
8897
@see [[m:Exception#backtrace_locations]]
@@ -112,8 +121,12 @@ end
112121

113122
e = get_exception { check_long_month(2) }
114123
p e.backtrace_locations
124+
#@since 3.4
125+
# => ["test.rb:4:in 'check_long_month'", "test.rb:15:in 'block in <main>'", "test.rb:9:in 'get_exception'", "test.rb:15:in '<main>'"]
126+
#@else
115127
# => ["test.rb:4:in `check_long_month'", "test.rb:15:in `block in <main>'", "test.rb:9:in `get_exception'", "test.rb:15:in `<main>'"]
116128
#@end
129+
#@end
117130

118131
@see [[m:Exception#backtrace]]
119132
#@end
@@ -149,7 +162,11 @@ begin
149162
raise "outer"
150163
end
151164
rescue
165+
#@since 3.4
166+
$!.backtrace # => ["/path/to/test.rb:5:in 'rescue in <main>'", "/path/to/test.rb:2:in '<main>'"]
167+
#@else
152168
$!.backtrace # => ["/path/to/test.rb:5:in `rescue in <main>'", "/path/to/test.rb:2:in `<main>'"]
169+
#@end
153170
$!.set_backtrace(["dummy1", "dummy2"])
154171
$!.backtrace # => ["dummy1", "dummy2"]
155172
end
@@ -271,11 +288,23 @@ end
271288
begin
272289
raise "test"
273290
rescue => e
291+
#@since 3.4
292+
p e.full_message # => "\e[1mTraceback \e[m(most recent call last):\ntest.rb:2:in '<main>': \e[1mtest (\e[4;1mRuntimeError\e[m\e[1m)\n\e[m"
293+
#@else
274294
p e.full_message # => "\e[1mTraceback \e[m(most recent call last):\ntest.rb:2:in `<main>': \e[1mtest (\e[4;1mRuntimeError\e[m\e[1m)\n\e[m"
295+
#@end
275296
$stderr = $stdout
297+
#@since 3.4
298+
p e.full_message # => "test.rb:2:in '<main>': test (RuntimeError)\n"
299+
#@else
276300
p e.full_message # => "test.rb:2:in `<main>': test (RuntimeError)\n"
301+
#@end
277302
$stderr = STDERR
303+
#@since 3.4
304+
p e.full_message # => "\e[1mTraceback \e[m(most recent call last):\ntest.rb:2:in '<main>': \e[1mtest (\e[4;1mRuntimeError\e[m\e[1m)\n\e[m"
305+
#@else
278306
p e.full_message # => "\e[1mTraceback \e[m(most recent call last):\ntest.rb:2:in `<main>': \e[1mtest (\e[4;1mRuntimeError\e[m\e[1m)\n\e[m"
307+
#@end
279308
end
280309
#@end
281310

refm/api/src/_builtin/IO

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,11 @@ outbuf は空文字列になります。
18541854
buf = f.read(3)
18551855
f.sysseek(0)
18561856
}
1857+
#@since 3.4
1858+
# => -:3:in 'sysseek': sysseek for buffered IO (IOError)
1859+
#@else
18571860
# => -:3:in `sysseek': sysseek for buffered IO (IOError)
1861+
#@end
18581862

18591863
File.open("/dev/null", "w") {|f|
18601864
f.print "foo"

refm/api/src/_builtin/Integer

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ self を文字コードとして見た時に、引数で与えたエンコーデ
7878
p 65.chr
7979
# => "A"
8080
p 12354.chr
81+
#@since 3.4
82+
# => 'chr': 12354 out of char range (RangeError)
83+
#@else
8184
# => `chr': 12354 out of char range (RangeError)
85+
#@end
8286

8387
p 12354.chr(Encoding::UTF_8)
8488
# => "あ"

refm/api/src/_builtin/Marshal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ obj を指定された出力先に再帰的に出力します。
3636

3737
#@samplecode 例
3838
p Marshal.dump(Hash.new {})
39+
#@since 3.4
40+
# => -:1:in 'dump': cannot dump hash with default proc (TypeError)
41+
#@else
3942
# => -:1:in `dump': cannot dump hash with default proc (TypeError)
4043
#@end
44+
#@end
4145

4246
マーシャルの動作を任意に定義することもできます。
4347

refm/api/src/_builtin/MatchData

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,12 @@ p $~.begin(0) # => 0
8282
p $~.begin(1) # => 0
8383
p $~.begin(2) # => 3
8484
p $~.begin(3) # => nil
85+
#@since 3.4
86+
p $~.begin(4) # => 'begin': index 4 out of matches (IndexError)
87+
#@else
8588
p $~.begin(4) # => `begin': index 4 out of matches (IndexError)
8689
#@end
90+
#@end
8791

8892
@see [[m:MatchData#end]]
8993

@@ -104,8 +108,12 @@ p $~.end(0) # => 6
104108
p $~.end(1) # => 3
105109
p $~.end(2) # => 6
106110
p $~.end(3) # => nil
111+
#@since 3.4
112+
p $~.end(4) # => 'end': index 4 out of matches (IndexError)
113+
#@else
107114
p $~.end(4) # => `end': index 4 out of matches (IndexError)
108115
#@end
116+
#@end
109117

110118
@see [[m:MatchData#begin]]
111119

@@ -207,8 +215,12 @@ p $~.offset(:year) # => [0, 4]
207215
p $~.offset('month') # => [5, 6]
208216
p $~.offset(:month) # => [5, 6]
209217
p $~.offset('day') # => [nil, nil]
218+
#@since 3.4
219+
p $~.offset('century') # => 'offset': undefined group name reference: century (IndexError)
220+
#@else
210221
p $~.offset('century') # => `offset': undefined group name reference: century (IndexError)
211222
#@end
223+
#@end
212224

213225
#@since 3.2
214226
@see [[m:MatchData#begin]], [[m:MatchData#end]], [[m:MatchData#byteoffset]]
@@ -248,8 +260,12 @@ p $~.byteoffset(:year) # => [0, 4]
248260
p $~.byteoffset('month') # => [7, 8]
249261
p $~.byteoffset(:month) # => [7, 8]
250262
p $~.byteoffset('day') # => [nil, nil]
263+
#@since 3.4
264+
p $~.byteoffset('century') # => 'offset': undefined group name reference: century (IndexError)
265+
#@else
251266
p $~.byteoffset('century') # => `offset': undefined group name reference: century (IndexError)
252267
#@end
268+
#@end
253269

254270
@see [[m:MatchData#offset]]
255271
#@end

refm/api/src/_builtin/Module

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,12 @@ p Baz < Bar # => true
158158
p Baz < Foo # => true
159159
p Baz < Qux # => nil
160160
p Baz > Qux # => nil
161-
161+
#@since 3.4
162+
p Foo < Object.new # => in '<': compared with non class/module (TypeError)
163+
#@else
162164
p Foo < Object.new # => in `<': compared with non class/module (TypeError)
163165
#@end
166+
#@end
164167

165168
--- <=(other) -> bool | nil
166169

@@ -373,8 +376,12 @@ class Foo
373376
autoload :Bar, '/tmp/bar.rb'
374377
end
375378
p Foo::Bar
379+
#@since 3.4
380+
#=> -:4:in '<main>': uninitialized constant Foo::Bar (NameError)
381+
#@else
376382
#=> -:4:in `<main>': uninitialized constant Foo::Bar (NameError)
377383
#@end
384+
#@end
378385

379386
@see [[m:Kernel.#autoload]]
380387

@@ -1005,8 +1012,12 @@ self の public インスタンスメソッド name をオブジェクト化し
10051012

10061013
#@samplecode 例
10071014
Kernel.public_instance_method(:object_id) #=> #<UnboundMethod: Kernel#object_id>
1015+
#@since 3.4
1016+
Kernel.public_instance_method(:p) # method 'p' for module 'Kernel' is private (NameError)
1017+
#@else
10081018
Kernel.public_instance_method(:p) # method `p' for module `Kernel' is private (NameError)
10091019
#@end
1020+
#@end
10101021

10111022
@see [[m:Module#instance_method]],[[m:Object#public_method]]
10121023

@@ -1129,7 +1140,11 @@ class Foo
11291140
private_class_method :foo
11301141
end
11311142

1143+
#@since 3.4
1144+
Foo.foo # NoMethodError: private method 'foo' called for Foo:Class
1145+
#@else
11321146
Foo.foo # NoMethodError: private method `foo' called for Foo:Class
1147+
#@end
11331148

11341149
Foo.public_class_method(:foo) # => Foo
11351150
Foo.foo # => "foo"
@@ -1657,8 +1672,12 @@ end
16571672

16581673
foo = Foo.new
16591674
p foo.foo1 # => 1
1675+
#@since 3.4
1676+
p foo.foo2 # => private method 'foo2' called for #<Foo:0x401b7628> (NoMethodError)
1677+
#@else
16601678
p foo.foo2 # => private method `foo2' called for #<Foo:0x401b7628> (NoMethodError)
16611679
#@end
1680+
#@end
16621681

16631682
--- protected() -> nil
16641683
--- protected(name) -> String | Symbol
@@ -1708,7 +1727,11 @@ p foo.foo2 # => private method `foo2' called for #<Foo:0x401b7628> (NoM
17081727
def foo() 1 end
17091728
p foo # => 1
17101729
# the toplevel default is private
1730+
#@since 3.4
1731+
p self.foo # => private method 'foo' called for #<Object:0x401c83b0> (NoMethodError)
1732+
#@else
17111733
p self.foo # => private method `foo' called for #<Object:0x401c83b0> (NoMethodError)
1734+
#@end
17121735

17131736
def bar() 2 end
17141737
public :bar # visibility changed (all access allowed)

refm/api/src/_builtin/Module.include

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ end
1919

2020
実行結果:
2121

22+
#@since 3.4
23+
-:3:in 'append_features': cyclic include detected (ArgumentError)
24+
from -:3:in 'include'
25+
#@else
2226
-:3:in `append_features': cyclic include detected (ArgumentError)
2327
from -:3:in `include'
28+
#@end
2429
from -:3
2530

2631

refm/api/src/_builtin/NameError

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
例:
66

77
bar
8+
#@since 3.4
9+
# => NameError: undefined local variable or method 'bar' for main:Object
10+
#@else
811
# => NameError: undefined local variable or method `bar' for main:Object
12+
#@end
913

1014
== Class Methods
1115

@@ -42,7 +46,11 @@
4246
begin
4347
foobar
4448
rescue NameError => err
49+
#@since 3.4
50+
p err # => #<NameError: undefined local variable or method 'foobar' for main:Object>
51+
#@else
4552
p err # => #<NameError: undefined local variable or method `foobar' for main:Object>
53+
#@end
4654
p err.name # => :foobar
4755
end
4856

@@ -55,8 +63,13 @@
5563
begin
5664
foobar
5765
rescue NameError => err
66+
#@since 3.4
67+
p err # => #<NameError: undefined local variable or method 'foobar' for main:Object>
68+
p err.to_s # => "undefined local variable or method 'foobar' for main:Object"
69+
#@else
5870
p err # => #<NameError: undefined local variable or method `foobar' for main:Object>
5971
p err.to_s # => "undefined local variable or method `foobar' for main:Object"
72+
#@end
6073
end
6174

6275
#@since 2.3.0

0 commit comments

Comments
 (0)