rbs 2.0.0 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +34 -0
  3. data/.github/workflows/ruby.yml +5 -0
  4. data/CHANGELOG.md +82 -0
  5. data/README.md +6 -1
  6. data/Rakefile +56 -21
  7. data/core/array.rbs +2866 -1086
  8. data/core/basic_object.rbs +150 -30
  9. data/core/binding.rbs +33 -0
  10. data/core/builtin.rbs +4 -4
  11. data/core/class.rbs +43 -5
  12. data/core/comparable.rbs +57 -0
  13. data/core/complex.rbs +170 -4
  14. data/core/constants.rbs +51 -0
  15. data/core/deprecated.rbs +7 -0
  16. data/core/dir.rbs +305 -20
  17. data/core/encoding.rbs +1214 -77
  18. data/core/enumerable.rbs +2173 -234
  19. data/core/enumerator.rbs +448 -182
  20. data/core/env.rbs +448 -1
  21. data/core/errno.rbs +1 -10
  22. data/core/errors.rbs +152 -2
  23. data/core/exception.rbs +201 -127
  24. data/core/false_class.rbs +27 -0
  25. data/core/fiber.rbs +118 -37
  26. data/core/fiber_error.rbs +8 -9
  27. data/core/file.rbs +1060 -142
  28. data/core/file_test.rbs +287 -32
  29. data/core/float.rbs +776 -300
  30. data/core/gc.rbs +185 -34
  31. data/core/global_variables.rbs +5 -1
  32. data/core/hash.rbs +1582 -649
  33. data/core/integer.rbs +974 -204
  34. data/core/io/buffer.rbs +710 -0
  35. data/core/io/wait.rbs +29 -8
  36. data/core/io.rbs +2438 -417
  37. data/core/kernel.rbs +2319 -318
  38. data/core/marshal.rbs +37 -2
  39. data/core/match_data.rbs +123 -6
  40. data/core/math.rbs +126 -6
  41. data/core/method.rbs +226 -102
  42. data/core/module.rbs +421 -45
  43. data/core/nil_class.rbs +64 -0
  44. data/core/numeric.rbs +620 -142
  45. data/core/object.rbs +453 -81
  46. data/core/object_space.rbs +92 -2
  47. data/core/proc.rbs +482 -285
  48. data/core/process.rbs +443 -34
  49. data/core/ractor.rbs +232 -9
  50. data/core/random.rbs +151 -52
  51. data/core/range.rbs +885 -160
  52. data/core/rational.rbs +122 -6
  53. data/core/rb_config.rbs +14 -4
  54. data/core/refinement.rbs +44 -0
  55. data/core/regexp.rbs +156 -14
  56. data/core/ruby_vm.rbs +42 -3
  57. data/core/signal.rbs +78 -39
  58. data/core/string.rbs +2123 -567
  59. data/core/string_io.rbs +204 -0
  60. data/core/struct.rbs +283 -28
  61. data/core/symbol.rbs +304 -30
  62. data/core/thread.rbs +1288 -688
  63. data/core/thread_group.rbs +66 -10
  64. data/core/time.rbs +643 -217
  65. data/core/trace_point.rbs +100 -12
  66. data/core/true_class.rbs +24 -0
  67. data/core/unbound_method.rbs +73 -7
  68. data/core/warning.rbs +37 -12
  69. data/docs/CONTRIBUTING.md +40 -34
  70. data/docs/stdlib.md +3 -102
  71. data/docs/syntax.md +54 -11
  72. data/ext/rbs_extension/extconf.rb +1 -0
  73. data/ext/rbs_extension/lexer.h +5 -0
  74. data/ext/rbs_extension/lexstate.c +6 -0
  75. data/ext/rbs_extension/parser.c +85 -10
  76. data/ext/rbs_extension/ruby_objs.c +4 -2
  77. data/ext/rbs_extension/ruby_objs.h +2 -2
  78. data/goodcheck.yml +0 -11
  79. data/lib/rbs/annotate/annotations.rb +197 -0
  80. data/lib/rbs/annotate/formatter.rb +80 -0
  81. data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
  82. data/lib/rbs/annotate/rdoc_source.rb +120 -0
  83. data/lib/rbs/annotate.rb +6 -0
  84. data/lib/rbs/ast/members.rb +21 -13
  85. data/lib/rbs/buffer.rb +17 -11
  86. data/lib/rbs/cli.rb +48 -1
  87. data/lib/rbs/definition_builder/method_builder.rb +28 -16
  88. data/lib/rbs/definition_builder.rb +6 -2
  89. data/lib/rbs/environment.rb +8 -4
  90. data/lib/rbs/location_aux.rb +12 -0
  91. data/lib/rbs/namespace.rb +1 -1
  92. data/lib/rbs/prototype/rb.rb +12 -0
  93. data/lib/rbs/type_alias_regularity.rb +6 -4
  94. data/lib/rbs/type_name.rb +1 -1
  95. data/lib/rbs/types.rb +1 -1
  96. data/lib/rbs/validator.rb +6 -0
  97. data/lib/rbs/version.rb +1 -1
  98. data/lib/rbs/writer.rb +54 -4
  99. data/lib/rbs.rb +0 -2
  100. data/schema/typeParam.json +3 -3
  101. data/sig/annotate/annotations.rbs +102 -0
  102. data/sig/annotate/formatter.rbs +24 -0
  103. data/sig/annotate/rdoc_annotater.rbs +82 -0
  104. data/sig/annotate/rdoc_source.rbs +30 -0
  105. data/sig/buffer.rbs +6 -2
  106. data/sig/cli.rbs +2 -0
  107. data/sig/collection/{collections.rbs → sources.rbs} +0 -0
  108. data/sig/location.rbs +6 -0
  109. data/sig/members.rbs +24 -18
  110. data/sig/method_builder.rbs +5 -4
  111. data/sig/method_types.rbs +5 -1
  112. data/sig/polyfill.rbs +78 -0
  113. data/sig/validator.rbs +3 -1
  114. data/sig/writer.rbs +79 -2
  115. data/stdlib/abbrev/0/abbrev.rbs +6 -0
  116. data/stdlib/abbrev/0/array.rbs +26 -0
  117. data/stdlib/base64/0/base64.rbs +31 -0
  118. data/stdlib/benchmark/0/benchmark.rbs +74 -3
  119. data/stdlib/bigdecimal/0/big_decimal.rbs +614 -165
  120. data/stdlib/bigdecimal-math/0/big_math.rbs +41 -64
  121. data/stdlib/cgi/0/core.rbs +649 -21
  122. data/stdlib/coverage/0/coverage.rbs +164 -2
  123. data/stdlib/csv/0/csv.rbs +2862 -398
  124. data/stdlib/date/0/date.rbs +483 -25
  125. data/stdlib/date/0/date_time.rbs +187 -12
  126. data/stdlib/dbm/0/dbm.rbs +152 -17
  127. data/stdlib/digest/0/digest.rbs +146 -0
  128. data/stdlib/erb/0/erb.rbs +65 -245
  129. data/stdlib/fiber/0/fiber.rbs +73 -91
  130. data/stdlib/fileutils/0/fileutils.rbs +301 -1
  131. data/stdlib/find/0/find.rbs +9 -0
  132. data/stdlib/forwardable/0/forwardable.rbs +65 -1
  133. data/stdlib/io-console/0/io-console.rbs +227 -15
  134. data/stdlib/ipaddr/0/ipaddr.rbs +161 -0
  135. data/stdlib/json/0/json.rbs +1147 -145
  136. data/stdlib/logger/0/formatter.rbs +24 -0
  137. data/stdlib/logger/0/log_device.rbs +64 -0
  138. data/stdlib/logger/0/logger.rbs +165 -13
  139. data/stdlib/logger/0/period.rbs +10 -0
  140. data/stdlib/logger/0/severity.rbs +26 -0
  141. data/stdlib/monitor/0/monitor.rbs +163 -0
  142. data/stdlib/mutex_m/0/mutex_m.rbs +35 -6
  143. data/stdlib/net-http/0/manifest.yaml +1 -0
  144. data/stdlib/net-http/0/net-http.rbs +1513 -683
  145. data/stdlib/nkf/0/nkf.rbs +372 -0
  146. data/stdlib/objspace/0/objspace.rbs +149 -90
  147. data/stdlib/openssl/0/openssl.rbs +8108 -71
  148. data/stdlib/optparse/0/optparse.rbs +487 -19
  149. data/stdlib/pathname/0/pathname.rbs +425 -124
  150. data/stdlib/prettyprint/0/prettyprint.rbs +120 -99
  151. data/stdlib/prime/0/integer-extension.rbs +20 -2
  152. data/stdlib/prime/0/prime.rbs +88 -21
  153. data/stdlib/pstore/0/pstore.rbs +102 -0
  154. data/stdlib/pty/0/pty.rbs +64 -14
  155. data/stdlib/resolv/0/resolv.rbs +420 -31
  156. data/stdlib/rubygems/0/basic_specification.rbs +4 -1
  157. data/stdlib/rubygems/0/config_file.rbs +33 -1
  158. data/stdlib/rubygems/0/dependency_installer.rbs +4 -3
  159. data/stdlib/rubygems/0/installer.rbs +13 -1
  160. data/stdlib/rubygems/0/path_support.rbs +4 -1
  161. data/stdlib/rubygems/0/platform.rbs +5 -1
  162. data/stdlib/rubygems/0/request_set.rbs +44 -2
  163. data/stdlib/rubygems/0/requirement.rbs +65 -2
  164. data/stdlib/rubygems/0/rubygems.rbs +407 -0
  165. data/stdlib/rubygems/0/source_list.rbs +13 -0
  166. data/stdlib/rubygems/0/specification.rbs +21 -1
  167. data/stdlib/rubygems/0/stream_ui.rbs +3 -1
  168. data/stdlib/rubygems/0/uninstaller.rbs +8 -1
  169. data/stdlib/rubygems/0/version.rbs +60 -157
  170. data/stdlib/securerandom/0/securerandom.rbs +44 -0
  171. data/stdlib/set/0/set.rbs +423 -109
  172. data/stdlib/shellwords/0/shellwords.rbs +55 -77
  173. data/stdlib/singleton/0/singleton.rbs +20 -0
  174. data/stdlib/socket/0/addrinfo.rbs +210 -9
  175. data/stdlib/socket/0/basic_socket.rbs +103 -11
  176. data/stdlib/socket/0/ip_socket.rbs +31 -9
  177. data/stdlib/socket/0/socket.rbs +586 -38
  178. data/stdlib/socket/0/tcp_server.rbs +22 -2
  179. data/stdlib/socket/0/tcp_socket.rbs +12 -1
  180. data/stdlib/socket/0/udp_socket.rbs +25 -2
  181. data/stdlib/socket/0/unix_server.rbs +22 -2
  182. data/stdlib/socket/0/unix_socket.rbs +45 -5
  183. data/stdlib/strscan/0/string_scanner.rbs +210 -9
  184. data/stdlib/tempfile/0/tempfile.rbs +58 -10
  185. data/stdlib/time/0/time.rbs +208 -116
  186. data/stdlib/timeout/0/timeout.rbs +10 -0
  187. data/stdlib/tmpdir/0/tmpdir.rbs +13 -4
  188. data/stdlib/tsort/0/cyclic.rbs +1 -0
  189. data/stdlib/tsort/0/interfaces.rbs +1 -0
  190. data/stdlib/tsort/0/tsort.rbs +42 -0
  191. data/stdlib/uri/0/common.rbs +57 -8
  192. data/stdlib/uri/0/file.rbs +55 -109
  193. data/stdlib/uri/0/ftp.rbs +6 -3
  194. data/stdlib/uri/0/generic.rbs +558 -329
  195. data/stdlib/uri/0/http.rbs +60 -114
  196. data/stdlib/uri/0/https.rbs +8 -102
  197. data/stdlib/uri/0/ldap.rbs +143 -137
  198. data/stdlib/uri/0/ldaps.rbs +8 -102
  199. data/stdlib/uri/0/mailto.rbs +3 -0
  200. data/stdlib/uri/0/rfc2396_parser.rbs +66 -26
  201. data/stdlib/uri/0/ws.rbs +6 -3
  202. data/stdlib/uri/0/wss.rbs +5 -3
  203. data/stdlib/yaml/0/dbm.rbs +151 -87
  204. data/stdlib/yaml/0/store.rbs +6 -0
  205. data/stdlib/zlib/0/zlib.rbs +90 -31
  206. metadata +18 -6
  207. data/lib/rbs/location.rb +0 -221
  208. data/sig/char_scanner.rbs +0 -9
data/core/proc.rbs CHANGED
@@ -1,205 +1,210 @@
1
- # A `Proc` object is an encapsulation of a block of code, which can be
2
- # stored in a local variable, passed to a method or another
3
- # [Proc](Proc), and can be called.
4
- # [Proc](Proc) is an essential concept in Ruby and a
5
- # core of its functional programming features.
1
+ # <!-- rdoc-file=proc.c -->
2
+ # A `Proc` object is an encapsulation of a block of code, which can be stored in
3
+ # a local variable, passed to a method or another Proc, and can be called. Proc
4
+ # is an essential concept in Ruby and a core of its functional programming
5
+ # features.
6
6
  #
7
- # ```ruby
8
- # square = Proc.new {|x| x**2 }
7
+ # square = Proc.new {|x| x**2 }
9
8
  #
10
- # square.call(3) #=> 9
11
- # # shorthands:
12
- # square.(3) #=> 9
13
- # square[3] #=> 9
14
- # ```
9
+ # square.call(3) #=> 9
10
+ # # shorthands:
11
+ # square.(3) #=> 9
12
+ # square[3] #=> 9
15
13
  #
16
- # [Proc](Proc) objects are *closures* , meaning they
17
- # remember and can use the entire context in which they were created.
14
+ # Proc objects are *closures*, meaning they remember and can use the entire
15
+ # context in which they were created.
18
16
  #
19
- # ```ruby
20
- # def gen_times(factor)
21
- # Proc.new {|n| n*factor } # remembers the value of factor at the moment of creation
22
- # end
17
+ # def gen_times(factor)
18
+ # Proc.new {|n| n*factor } # remembers the value of factor at the moment of creation
19
+ # end
23
20
  #
24
- # times3 = gen_times(3)
25
- # times5 = gen_times(5)
21
+ # times3 = gen_times(3)
22
+ # times5 = gen_times(5)
26
23
  #
27
- # times3.call(12) #=> 36
28
- # times5.call(5) #=> 25
29
- # times3.call(times5.call(4)) #=> 60
30
- # ```
24
+ # times3.call(12) #=> 36
25
+ # times5.call(5) #=> 25
26
+ # times3.call(times5.call(4)) #=> 60
31
27
  #
28
+ # ## Creation
32
29
  #
33
- # There are several methods to create a [Proc](Proc)
30
+ # There are several methods to create a Proc
34
31
  #
35
- # - Use the [Proc](Proc) class constructor:
32
+ # * Use the Proc class constructor:
36
33
  #
37
- # ```ruby
38
- # proc1 = Proc.new {|x| x**2 }
39
- # ```
34
+ # proc1 = Proc.new {|x| x**2 }
40
35
  #
41
- # - Use the
42
- # [Kernel\#proc](https://ruby-doc.org/core-2.6.3/Kernel.html#method-i-proc)
43
- # method as a shorthand of
44
- # [::new](Proc#method-c-new):
36
+ # * Use the Kernel#proc method as a shorthand of Proc.new:
45
37
  #
46
- # ```ruby
47
- # proc2 = proc {|x| x**2 }
48
- # ```
38
+ # proc2 = proc {|x| x**2 }
49
39
  #
50
- # - Receiving a block of code into proc argument (note the `&` ):
40
+ # * Receiving a block of code into proc argument (note the `&`):
51
41
  #
52
- # ```ruby
53
- # def make_proc(&block)
54
- # block
55
- # end
42
+ # def make_proc(&block)
43
+ # block
44
+ # end
45
+ #
46
+ # proc3 = make_proc {|x| x**2 }
56
47
  #
57
- # proc3 = make_proc {|x| x**2 }
58
- # ```
48
+ # * Construct a proc with lambda semantics using the Kernel#lambda method (see
49
+ # below for explanations about lambdas):
59
50
  #
60
- # - Construct a proc with lambda semantics using the
61
- # [Kernel\#lambda](https://ruby-doc.org/core-2.6.3/Kernel.html#method-i-lambda)
62
- # method (see below for explanations about lambdas):
51
+ # lambda1 = lambda {|x| x**2 }
63
52
  #
64
- # ```ruby
65
- # lambda1 = lambda {|x| x**2 }
66
- # ```
53
+ # * Use the [Lambda proc
54
+ # literal](doc/syntax/literals_rdoc.html#label-Lambda+Proc+Literals) syntax
55
+ # (also constructs a proc with lambda semantics):
67
56
  #
68
- # - Use the Lambda literal syntax (also constructs a proc with lambda
69
- # semantics):
57
+ # lambda2 = ->(x) { x**2 }
70
58
  #
71
- # ```ruby
72
- # lambda2 = ->(x) { x**2 }
73
- # ```
74
59
  #
60
+ # ## Lambda and non-lambda semantics
75
61
  #
76
62
  # Procs are coming in two flavors: lambda and non-lambda (regular procs).
77
63
  # Differences are:
78
64
  #
79
- # - In lambdas, `return` means exit from this lambda;
80
- #
81
- # - In regular procs, `return` means exit from embracing method (and
82
- # will throw `LocalJumpError` if invoked outside the method);
83
- #
84
- # - In lambdas, arguments are treated in the same way as in methods:
85
- # strict, with `ArgumentError` for mismatching argument number, and no
86
- # additional argument processing;
65
+ # * In lambdas, `return` and `break` means exit from this lambda;
66
+ # * In non-lambda procs, `return` means exit from embracing method (and will
67
+ # throw `LocalJumpError` if invoked outside the method);
68
+ # * In non-lambda procs, `break` means exit from the method which the block
69
+ # given for. (and will throw `LocalJumpError` if invoked after the method
70
+ # returns);
71
+ # * In lambdas, arguments are treated in the same way as in methods: strict,
72
+ # with `ArgumentError` for mismatching argument number, and no additional
73
+ # argument processing;
74
+ # * Regular procs accept arguments more generously: missing arguments are
75
+ # filled with `nil`, single Array arguments are deconstructed if the proc
76
+ # has multiple arguments, and there is no error raised on extra arguments.
87
77
  #
88
- # - Regular procs accept arguments more generously: missing arguments
89
- # are filled with `nil`, single
90
- # [Array](https://ruby-doc.org/core-2.6.3/Array.html) arguments are
91
- # deconstructed if the proc has multiple arguments, and there is no
92
- # error raised on extra arguments.
93
78
  #
94
79
  # Examples:
95
80
  #
96
- # ```ruby
97
- # p = proc {|x, y| "x=#{x}, y=#{y}" }
98
- # p.call(1, 2) #=> "x=1, y=2"
99
- # p.call([1, 2]) #=> "x=1, y=2", array deconstructed
100
- # p.call(1, 2, 8) #=> "x=1, y=2", extra argument discarded
101
- # p.call(1) #=> "x=1, y=", nil substituted instead of error
102
- #
103
- # l = lambda {|x, y| "x=#{x}, y=#{y}" }
104
- # l.call(1, 2) #=> "x=1, y=2"
105
- # l.call([1, 2]) # ArgumentError: wrong number of arguments (given 1, expected 2)
106
- # l.call(1, 2, 8) # ArgumentError: wrong number of arguments (given 3, expected 2)
107
- # l.call(1) # ArgumentError: wrong number of arguments (given 1, expected 2)
108
- #
109
- # def test_return
110
- # -> { return 3 }.call # just returns from lambda into method body
111
- # proc { return 4 }.call # returns from method
112
- # return 5
113
- # end
81
+ # # +return+ in non-lambda proc, +b+, exits +m2+.
82
+ # # (The block +{ return }+ is given for +m1+ and embraced by +m2+.)
83
+ # $a = []; def m1(&b) b.call; $a << :m1 end; def m2() m1 { return }; $a << :m2 end; m2; p $a
84
+ # #=> []
85
+ #
86
+ # # +break+ in non-lambda proc, +b+, exits +m1+.
87
+ # # (The block +{ break }+ is given for +m1+ and embraced by +m2+.)
88
+ # $a = []; def m1(&b) b.call; $a << :m1 end; def m2() m1 { break }; $a << :m2 end; m2; p $a
89
+ # #=> [:m2]
90
+ #
91
+ # # +next+ in non-lambda proc, +b+, exits the block.
92
+ # # (The block +{ next }+ is given for +m1+ and embraced by +m2+.)
93
+ # $a = []; def m1(&b) b.call; $a << :m1 end; def m2() m1 { next }; $a << :m2 end; m2; p $a
94
+ # #=> [:m1, :m2]
95
+ #
96
+ # # Using +proc+ method changes the behavior as follows because
97
+ # # The block is given for +proc+ method and embraced by +m2+.
98
+ # $a = []; def m1(&b) b.call; $a << :m1 end; def m2() m1(&proc { return }); $a << :m2 end; m2; p $a
99
+ # #=> []
100
+ # $a = []; def m1(&b) b.call; $a << :m1 end; def m2() m1(&proc { break }); $a << :m2 end; m2; p $a
101
+ # # break from proc-closure (LocalJumpError)
102
+ # $a = []; def m1(&b) b.call; $a << :m1 end; def m2() m1(&proc { next }); $a << :m2 end; m2; p $a
103
+ # #=> [:m1, :m2]
104
+ #
105
+ # # +return+, +break+ and +next+ in the stubby lambda exits the block.
106
+ # # (+lambda+ method behaves same.)
107
+ # # (The block is given for stubby lambda syntax and embraced by +m2+.)
108
+ # $a = []; def m1(&b) b.call; $a << :m1 end; def m2() m1(&-> { return }); $a << :m2 end; m2; p $a
109
+ # #=> [:m1, :m2]
110
+ # $a = []; def m1(&b) b.call; $a << :m1 end; def m2() m1(&-> { break }); $a << :m2 end; m2; p $a
111
+ # #=> [:m1, :m2]
112
+ # $a = []; def m1(&b) b.call; $a << :m1 end; def m2() m1(&-> { next }); $a << :m2 end; m2; p $a
113
+ # #=> [:m1, :m2]
114
+ #
115
+ # p = proc {|x, y| "x=#{x}, y=#{y}" }
116
+ # p.call(1, 2) #=> "x=1, y=2"
117
+ # p.call([1, 2]) #=> "x=1, y=2", array deconstructed
118
+ # p.call(1, 2, 8) #=> "x=1, y=2", extra argument discarded
119
+ # p.call(1) #=> "x=1, y=", nil substituted instead of error
120
+ #
121
+ # l = lambda {|x, y| "x=#{x}, y=#{y}" }
122
+ # l.call(1, 2) #=> "x=1, y=2"
123
+ # l.call([1, 2]) # ArgumentError: wrong number of arguments (given 1, expected 2)
124
+ # l.call(1, 2, 8) # ArgumentError: wrong number of arguments (given 3, expected 2)
125
+ # l.call(1) # ArgumentError: wrong number of arguments (given 1, expected 2)
126
+ #
127
+ # def test_return
128
+ # -> { return 3 }.call # just returns from lambda into method body
129
+ # proc { return 4 }.call # returns from method
130
+ # return 5
131
+ # end
114
132
  #
115
- # test_return # => 4, return from proc
116
- # ```
133
+ # test_return # => 4, return from proc
117
134
  #
118
135
  # Lambdas are useful as self-sufficient functions, in particular useful as
119
136
  # arguments to higher-order functions, behaving exactly like Ruby methods.
120
137
  #
121
138
  # Procs are useful for implementing iterators:
122
139
  #
123
- # ```ruby
124
- # def test
125
- # [[1, 2], [3, 4], [5, 6]].map {|a, b| return a if a + b > 10 }
126
- # # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
127
- # end
128
- # ```
129
- #
130
- # Inside `map`, the block of code is treated as a regular (non-lambda)
131
- # proc, which means that the internal arrays will be deconstructed to
132
- # pairs of arguments, and `return` will exit from the method `test` . That
133
- # would not be possible with a stricter lambda.
134
- #
135
- # You can tell a lambda from a regular proc by using the
136
- # [lambda?](Proc#method-i-lambda-3F) instance method.
137
- #
138
- # Lambda semantics is typically preserved during the proc lifetime,
139
- # including `&` -deconstruction to a block of code:
140
- #
141
- # ```ruby
142
- # p = proc {|x, y| x }
143
- # l = lambda {|x, y| x }
144
- # [[1, 2], [3, 4]].map(&p) #=> [1, 2]
145
- # [[1, 2], [3, 4]].map(&l) # ArgumentError: wrong number of arguments (given 1, expected 2)
146
- # ```
147
- #
148
- # The only exception is dynamic method definition: even if defined by
149
- # passing a non-lambda proc, methods still have normal semantics of
150
- # argument checking.
151
- #
152
- # ```ruby
153
- # class C
154
- # define_method(:e, &proc {})
155
- # end
156
- # C.new.e(1,2) #=> ArgumentError
157
- # C.new.method(:e).to_proc.lambda? #=> true
158
- # ```
140
+ # def test
141
+ # [[1, 2], [3, 4], [5, 6]].map {|a, b| return a if a + b > 10 }
142
+ # # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
143
+ # end
144
+ #
145
+ # Inside `map`, the block of code is treated as a regular (non-lambda) proc,
146
+ # which means that the internal arrays will be deconstructed to pairs of
147
+ # arguments, and `return` will exit from the method `test`. That would not be
148
+ # possible with a stricter lambda.
149
+ #
150
+ # You can tell a lambda from a regular proc by using the #lambda? instance
151
+ # method.
152
+ #
153
+ # Lambda semantics is typically preserved during the proc lifetime, including
154
+ # `&`-deconstruction to a block of code:
155
+ #
156
+ # p = proc {|x, y| x }
157
+ # l = lambda {|x, y| x }
158
+ # [[1, 2], [3, 4]].map(&p) #=> [1, 3]
159
+ # [[1, 2], [3, 4]].map(&l) # ArgumentError: wrong number of arguments (given 1, expected 2)
160
+ #
161
+ # The only exception is dynamic method definition: even if defined by passing a
162
+ # non-lambda proc, methods still have normal semantics of argument checking.
163
+ #
164
+ # class C
165
+ # define_method(:e, &proc {})
166
+ # end
167
+ # C.new.e(1,2) #=> ArgumentError
168
+ # C.new.method(:e).to_proc.lambda? #=> true
159
169
  #
160
170
  # This exception ensures that methods never have unusual argument passing
161
- # conventions, and makes it easy to have wrappers defining methods that
162
- # behave as usual.
171
+ # conventions, and makes it easy to have wrappers defining methods that behave
172
+ # as usual.
163
173
  #
164
- # ```ruby
165
- # class C
166
- # def self.def2(name, &body)
167
- # define_method(name, &body)
168
- # end
174
+ # class C
175
+ # def self.def2(name, &body)
176
+ # define_method(name, &body)
177
+ # end
169
178
  #
170
- # def2(:f) {}
171
- # end
172
- # C.new.f(1,2) #=> ArgumentError
173
- # ```
179
+ # def2(:f) {}
180
+ # end
181
+ # C.new.f(1,2) #=> ArgumentError
174
182
  #
175
- # The wrapper *def2* receives `body` as a non-lambda proc, yet defines a
176
- # method which has normal semantics.
183
+ # The wrapper `def2` receives *body* as a non-lambda proc, yet defines a method
184
+ # which has normal semantics.
177
185
  #
186
+ # ## Conversion of other objects to procs
178
187
  #
179
- # Any object that implements the `to_proc` method can be converted into a
180
- # proc by the `&` operator, and therefore con be consumed by iterators.
188
+ # Any object that implements the `to_proc` method can be converted into a proc
189
+ # by the `&` operator, and therefore can be consumed by iterators.
181
190
  #
182
- # ```ruby
183
- # class Greater
184
- # def initialize(greating)
185
- # @greating = greating
186
- # end
191
+ # class Greeter
192
+ # def initialize(greeting)
193
+ # @greeting = greeting
194
+ # end
187
195
  #
188
- # def to_proc
189
- # proc {|name| "#{@greating}, #{name}!" }
190
- # end
191
- # end
196
+ # def to_proc
197
+ # proc {|name| "#{@greeting}, #{name}!" }
198
+ # end
199
+ # end
192
200
  #
193
- # hi = Greater.new("Hi")
194
- # hey = Greater.new("Hey")
195
- # ["Bob", "Jane"].map(&hi) #=> ["Hi, Bob!", "Hi, Jane!"]
196
- # ["Bob", "Jane"].map(&hey) #=> ["Hey, Bob!", "Hey, Jane!"]
197
- # ```
201
+ # hi = Greeter.new("Hi")
202
+ # hey = Greeter.new("Hey")
203
+ # ["Bob", "Jane"].map(&hi) #=> ["Hi, Bob!", "Hi, Jane!"]
204
+ # ["Bob", "Jane"].map(&hey) #=> ["Hey, Bob!", "Hey, Jane!"]
198
205
  #
199
- # Of the Ruby core classes, this method is implemented by
200
- # [Symbol](https://ruby-doc.org/core-2.6.3/Symbol.html),
201
- # [Method](https://ruby-doc.org/core-2.6.3/Method.html), and
202
- # [Hash](https://ruby-doc.org/core-2.6.3/Hash.html).
206
+ # Of the Ruby core classes, this method is implemented by Symbol, Method, and
207
+ # Hash.
203
208
  #
204
209
  # :to_s.to_proc.call(1) #=> "1"
205
210
  # [1, 2].map(&:to_s) #=> ["1", "2"]
@@ -209,19 +214,96 @@
209
214
  #
210
215
  # {test: 1}.to_proc.call(:test) #=> 1
211
216
  # %i[test many keys].map(&{test: 1}) #=> [1, nil, nil]
217
+ #
218
+ # ## Orphaned Proc
219
+ #
220
+ # `return` and `break` in a block exit a method. If a Proc object is generated
221
+ # from the block and the Proc object survives until the method is returned,
222
+ # `return` and `break` cannot work. In such case, `return` and `break` raises
223
+ # LocalJumpError. A Proc object in such situation is called as orphaned Proc
224
+ # object.
225
+ #
226
+ # Note that the method to exit is different for `return` and `break`. There is a
227
+ # situation that orphaned for `break` but not orphaned for `return`.
228
+ #
229
+ # def m1(&b) b.call end; def m2(); m1 { return } end; m2 # ok
230
+ # def m1(&b) b.call end; def m2(); m1 { break } end; m2 # ok
231
+ #
232
+ # def m1(&b) b end; def m2(); m1 { return }.call end; m2 # ok
233
+ # def m1(&b) b end; def m2(); m1 { break }.call end; m2 # LocalJumpError
234
+ #
235
+ # def m1(&b) b end; def m2(); m1 { return } end; m2.call # LocalJumpError
236
+ # def m1(&b) b end; def m2(); m1 { break } end; m2.call # LocalJumpError
237
+ #
238
+ # Since `return` and `break` exits the block itself in lambdas, lambdas cannot
239
+ # be orphaned.
240
+ #
241
+ # ## Numbered parameters
242
+ #
243
+ # Numbered parameters are implicitly defined block parameters intended to
244
+ # simplify writing short blocks:
245
+ #
246
+ # # Explicit parameter:
247
+ # %w[test me please].each { |str| puts str.upcase } # prints TEST, ME, PLEASE
248
+ # (1..5).map { |i| i**2 } # => [1, 4, 9, 16, 25]
249
+ #
250
+ # # Implicit parameter:
251
+ # %w[test me please].each { puts _1.upcase } # prints TEST, ME, PLEASE
252
+ # (1..5).map { _1**2 } # => [1, 4, 9, 16, 25]
253
+ #
254
+ # Parameter names from `_1` to `_9` are supported:
255
+ #
256
+ # [10, 20, 30].zip([40, 50, 60], [70, 80, 90]).map { _1 + _2 + _3 }
257
+ # # => [120, 150, 180]
258
+ #
259
+ # Though, it is advised to resort to them wisely, probably limiting yourself to
260
+ # `_1` and `_2`, and to one-line blocks.
261
+ #
262
+ # Numbered parameters can't be used together with explicitly named ones:
263
+ #
264
+ # [10, 20, 30].map { |x| _1**2 }
265
+ # # SyntaxError (ordinary parameter is defined)
266
+ #
267
+ # To avoid conflicts, naming local variables or method arguments `_1`, `_2` and
268
+ # so on, causes a warning.
269
+ #
270
+ # _1 = 'test'
271
+ # # warning: `_1' is reserved as numbered parameter
272
+ #
273
+ # Using implicit numbered parameters affects block's arity:
274
+ #
275
+ # p = proc { _1 + _2 }
276
+ # l = lambda { _1 + _2 }
277
+ # p.parameters # => [[:opt, :_1], [:opt, :_2]]
278
+ # p.arity # => 2
279
+ # l.parameters # => [[:req, :_1], [:req, :_2]]
280
+ # l.arity # => 2
281
+ #
282
+ # Blocks with numbered parameters can't be nested:
283
+ #
284
+ # %w[test me].each { _1.each_char { p _1 } }
285
+ # # SyntaxError (numbered parameter is already used in outer block here)
286
+ # # %w[test me].each { _1.each_char { p _1 } }
287
+ # # ^~
288
+ #
289
+ # Numbered parameters were introduced in Ruby 2.7.
290
+ #
212
291
  class Proc < Object
213
292
  def clone: () -> self
214
293
 
215
- # Returns the number of mandatory arguments. If the block is declared to
216
- # take no arguments, returns 0. If the block is known to take exactly n
217
- # arguments, returns n. If the block has optional arguments, returns -n-1,
218
- # where n is the number of mandatory arguments, with the exception for
219
- # blocks that are not lambdas and have only a finite number of optional
220
- # arguments; in this latter case, returns n. Keyword arguments will be
221
- # considered as a single additional argument, that argument being
222
- # mandatory if any keyword argument is mandatory. A `proc` with no
223
- # argument declarations is the same as a block declaring `||` as its
224
- # arguments.
294
+ # <!--
295
+ # rdoc-file=proc.c
296
+ # - prc.arity -> integer
297
+ # -->
298
+ # Returns the number of mandatory arguments. If the block is declared to take no
299
+ # arguments, returns 0. If the block is known to take exactly n arguments,
300
+ # returns n. If the block has optional arguments, returns -n-1, where n is the
301
+ # number of mandatory arguments, with the exception for blocks that are not
302
+ # lambdas and have only a finite number of optional arguments; in this latter
303
+ # case, returns n. Keyword arguments will be considered as a single additional
304
+ # argument, that argument being mandatory if any keyword argument is mandatory.
305
+ # A #proc with no argument declarations is the same as a block declaring `||` as
306
+ # its arguments.
225
307
  #
226
308
  # proc {}.arity #=> 0
227
309
  # proc { || }.arity #=> 0
@@ -246,185 +328,300 @@ class Proc < Object
246
328
  # lambda { |(a, b), c=0| }.arity #=> -2
247
329
  # proc { |a, x:0, y:0| }.arity #=> 1
248
330
  # lambda { |a, x:0, y:0| }.arity #=> -2
331
+ #
249
332
  def arity: () -> Integer
250
333
 
251
- # Returns the binding associated with *prc* .
334
+ # <!--
335
+ # rdoc-file=proc.c
336
+ # - prc.binding -> binding
337
+ # -->
338
+ # Returns the binding associated with *prc*.
339
+ #
340
+ # def fred(param)
341
+ # proc {}
342
+ # end
252
343
  #
253
- # ```ruby
254
- # def fred(param)
255
- # proc {}
256
- # end
344
+ # b = fred(99)
345
+ # eval("param", b.binding) #=> 99
257
346
  #
258
- # b = fred(99)
259
- # eval("param", b.binding) #=> 99
260
- # ```
261
347
  def binding: () -> Binding
262
348
 
349
+ # <!--
350
+ # rdoc-file=proc.c
351
+ # - prc.call(params,...) -> obj
352
+ # - prc[params,...] -> obj
353
+ # - prc.(params,...) -> obj
354
+ # - prc.yield(params,...) -> obj
355
+ # -->
356
+ # Invokes the block, setting the block's parameters to the values in *params*
357
+ # using something close to method calling semantics. Returns the value of the
358
+ # last expression evaluated in the block.
359
+ #
360
+ # a_proc = Proc.new {|scalar, *values| values.map {|value| value*scalar } }
361
+ # a_proc.call(9, 1, 2, 3) #=> [9, 18, 27]
362
+ # a_proc[9, 1, 2, 3] #=> [9, 18, 27]
363
+ # a_proc.(9, 1, 2, 3) #=> [9, 18, 27]
364
+ # a_proc.yield(9, 1, 2, 3) #=> [9, 18, 27]
365
+ #
366
+ # Note that `prc.()` invokes `prc.call()` with the parameters given. It's
367
+ # syntactic sugar to hide "call".
368
+ #
369
+ # For procs created using #lambda or `->()` an error is generated if the wrong
370
+ # number of parameters are passed to the proc. For procs created using Proc.new
371
+ # or Kernel.proc, extra parameters are silently discarded and missing parameters
372
+ # are set to `nil`.
373
+ #
374
+ # a_proc = proc {|a,b| [a,b] }
375
+ # a_proc.call(1) #=> [1, nil]
376
+ #
377
+ # a_proc = lambda {|a,b| [a,b] }
378
+ # a_proc.call(1) # ArgumentError: wrong number of arguments (given 1, expected 2)
379
+ #
380
+ # See also Proc#lambda?.
381
+ #
263
382
  def call: (*untyped arg0) -> untyped
264
383
 
384
+ # <!-- rdoc-file=proc.c -->
385
+ # Invokes the block, setting the block's parameters to the values in *params*
386
+ # using something close to method calling semantics. Returns the value of the
387
+ # last expression evaluated in the block.
388
+ #
389
+ # a_proc = Proc.new {|scalar, *values| values.map {|value| value*scalar } }
390
+ # a_proc.call(9, 1, 2, 3) #=> [9, 18, 27]
391
+ # a_proc[9, 1, 2, 3] #=> [9, 18, 27]
392
+ # a_proc.(9, 1, 2, 3) #=> [9, 18, 27]
393
+ # a_proc.yield(9, 1, 2, 3) #=> [9, 18, 27]
394
+ #
395
+ # Note that `prc.()` invokes `prc.call()` with the parameters given. It's
396
+ # syntactic sugar to hide "call".
397
+ #
398
+ # For procs created using #lambda or `->()` an error is generated if the wrong
399
+ # number of parameters are passed to the proc. For procs created using Proc.new
400
+ # or Kernel.proc, extra parameters are silently discarded and missing parameters
401
+ # are set to `nil`.
402
+ #
403
+ # a_proc = proc {|a,b| [a,b] }
404
+ # a_proc.call(1) #=> [1, nil]
405
+ #
406
+ # a_proc = lambda {|a,b| [a,b] }
407
+ # a_proc.call(1) # ArgumentError: wrong number of arguments (given 1, expected 2)
408
+ #
409
+ # See also Proc#lambda?.
410
+ #
265
411
  def []: (*untyped arg0) -> untyped
266
412
 
413
+ # <!--
414
+ # rdoc-file=proc.c
415
+ # - prc.curry -> a_proc
416
+ # - prc.curry(arity) -> a_proc
417
+ # -->
418
+ # Returns a curried proc. If the optional *arity* argument is given, it
419
+ # determines the number of arguments. A curried proc receives some arguments. If
420
+ # a sufficient number of arguments are supplied, it passes the supplied
421
+ # arguments to the original proc and returns the result. Otherwise, returns
422
+ # another curried proc that takes the rest of arguments.
423
+ #
424
+ # b = proc {|x, y, z| (x||0) + (y||0) + (z||0) }
425
+ # p b.curry[1][2][3] #=> 6
426
+ # p b.curry[1, 2][3, 4] #=> 6
427
+ # p b.curry(5)[1][2][3][4][5] #=> 6
428
+ # p b.curry(5)[1, 2][3, 4][5] #=> 6
429
+ # p b.curry(1)[1] #=> 1
430
+ #
431
+ # b = proc {|x, y, z, *w| (x||0) + (y||0) + (z||0) + w.inject(0, &:+) }
432
+ # p b.curry[1][2][3] #=> 6
433
+ # p b.curry[1, 2][3, 4] #=> 10
434
+ # p b.curry(5)[1][2][3][4][5] #=> 15
435
+ # p b.curry(5)[1, 2][3, 4][5] #=> 15
436
+ # p b.curry(1)[1] #=> 1
437
+ #
438
+ # b = lambda {|x, y, z| (x||0) + (y||0) + (z||0) }
439
+ # p b.curry[1][2][3] #=> 6
440
+ # p b.curry[1, 2][3, 4] #=> wrong number of arguments (given 4, expected 3)
441
+ # p b.curry(5) #=> wrong number of arguments (given 5, expected 3)
442
+ # p b.curry(1) #=> wrong number of arguments (given 1, expected 3)
443
+ #
444
+ # b = lambda {|x, y, z, *w| (x||0) + (y||0) + (z||0) + w.inject(0, &:+) }
445
+ # p b.curry[1][2][3] #=> 6
446
+ # p b.curry[1, 2][3, 4] #=> 10
447
+ # p b.curry(5)[1][2][3][4][5] #=> 15
448
+ # p b.curry(5)[1, 2][3, 4][5] #=> 15
449
+ # p b.curry(1) #=> wrong number of arguments (given 1, expected 3)
450
+ #
451
+ # b = proc { :foo }
452
+ # p b.curry[] #=> :foo
453
+ #
267
454
  def curry: (?_ToInt arity) -> Proc
268
455
 
456
+ # <!--
457
+ # rdoc-file=proc.c
458
+ # - prc.hash -> integer
459
+ # -->
269
460
  # Returns a hash value corresponding to proc body.
270
461
  #
271
- # See also Object\#hash.
462
+ # See also Object#hash.
463
+ #
272
464
  def hash: () -> Integer
273
465
 
466
+ # <!--
467
+ # rdoc-file=proc.c
468
+ # - Proc.new {|...| block } -> a_proc
469
+ # -->
470
+ # Creates a new Proc object, bound to the current context.
471
+ #
472
+ # proc = Proc.new { "hello" }
473
+ # proc.call #=> "hello"
474
+ #
475
+ # Raises ArgumentError if called without a block.
476
+ #
477
+ # Proc.new #=> ArgumentError
478
+ #
274
479
  def initialize: () { (*untyped) -> untyped } -> void
275
480
 
276
- # Returns `true` for a [Proc](Proc.downloaded.ruby_doc) object for which
277
- # argument handling is rigid. Such procs are typically generated by
278
- # `lambda` .
481
+ # <!--
482
+ # rdoc-file=proc.c
483
+ # - prc.lambda? -> true or false
484
+ # -->
485
+ # Returns `true` if a Proc object is lambda. `false` if non-lambda.
279
486
  #
280
- # A [Proc](Proc.downloaded.ruby_doc) object generated by `proc` ignores
281
- # extra arguments.
487
+ # The lambda-ness affects argument handling and the behavior of `return` and
488
+ # `break`.
282
489
  #
283
- # ```ruby
284
- # proc {|a,b| [a,b] }.call(1,2,3) #=> [1,2]
285
- # ```
490
+ # A Proc object generated by `proc` ignores extra arguments.
491
+ #
492
+ # proc {|a,b| [a,b] }.call(1,2,3) #=> [1,2]
286
493
  #
287
494
  # It provides `nil` for missing arguments.
288
495
  #
289
- # ```ruby
290
- # proc {|a,b| [a,b] }.call(1) #=> [1,nil]
291
- # ```
496
+ # proc {|a,b| [a,b] }.call(1) #=> [1,nil]
292
497
  #
293
498
  # It expands a single array argument.
294
499
  #
295
- # ```ruby
296
- # proc {|a,b| [a,b] }.call([1,2]) #=> [1,2]
297
- # ```
500
+ # proc {|a,b| [a,b] }.call([1,2]) #=> [1,2]
298
501
  #
299
- # A [Proc](Proc.downloaded.ruby_doc) object generated by `lambda` doesnt
300
- # have such tricks.
502
+ # A Proc object generated by `lambda` doesn't have such tricks.
301
503
  #
302
- # ```ruby
303
- # lambda {|a,b| [a,b] }.call(1,2,3) #=> ArgumentError
304
- # lambda {|a,b| [a,b] }.call(1) #=> ArgumentError
305
- # lambda {|a,b| [a,b] }.call([1,2]) #=> ArgumentError
306
- # ```
504
+ # lambda {|a,b| [a,b] }.call(1,2,3) #=> ArgumentError
505
+ # lambda {|a,b| [a,b] }.call(1) #=> ArgumentError
506
+ # lambda {|a,b| [a,b] }.call([1,2]) #=> ArgumentError
307
507
  #
308
- # [\#lambda?](Proc.downloaded.ruby_doc#method-i-lambda-3F) is a predicate
309
- # for the tricks. It returns `true` if no tricks apply.
508
+ # Proc#lambda? is a predicate for the tricks. It returns `true` if no tricks
509
+ # apply.
310
510
  #
311
- # ```ruby
312
- # lambda {}.lambda? #=> true
313
- # proc {}.lambda? #=> false
314
- # ```
511
+ # lambda {}.lambda? #=> true
512
+ # proc {}.lambda? #=> false
315
513
  #
316
- # [::new](Proc.downloaded.ruby_doc#method-c-new) is the same as `proc` .
514
+ # Proc.new is the same as `proc`.
317
515
  #
318
- # ```ruby
319
- # Proc.new {}.lambda? #=> false
320
- # ```
516
+ # Proc.new {}.lambda? #=> false
321
517
  #
322
- # `lambda`, `proc` and [::new](Proc.downloaded.ruby_doc#method-c-new)
323
- # preserve the tricks of a [Proc](Proc.downloaded.ruby_doc) object given
324
- # by `&` argument.
518
+ # `lambda`, `proc` and Proc.new preserve the tricks of a Proc object given by
519
+ # `&` argument.
325
520
  #
326
- # ```ruby
327
- # lambda(&lambda {}).lambda? #=> true
328
- # proc(&lambda {}).lambda? #=> true
329
- # Proc.new(&lambda {}).lambda? #=> true
521
+ # lambda(&lambda {}).lambda? #=> true
522
+ # proc(&lambda {}).lambda? #=> true
523
+ # Proc.new(&lambda {}).lambda? #=> true
330
524
  #
331
- # lambda(&proc {}).lambda? #=> false
332
- # proc(&proc {}).lambda? #=> false
333
- # Proc.new(&proc {}).lambda? #=> false
334
- # ```
525
+ # lambda(&proc {}).lambda? #=> false
526
+ # proc(&proc {}).lambda? #=> false
527
+ # Proc.new(&proc {}).lambda? #=> false
335
528
  #
336
- # A [Proc](Proc.downloaded.ruby_doc) object generated by `&` argument has
337
- # the tricks
529
+ # A Proc object generated by `&` argument has the tricks
338
530
  #
339
- # ```ruby
340
- # def n(&b) b.lambda? end
341
- # n {} #=> false
342
- # ```
531
+ # def n(&b) b.lambda? end
532
+ # n {} #=> false
343
533
  #
344
- # The `&` argument preserves the tricks if a
345
- # [Proc](Proc.downloaded.ruby_doc) object is given by `&` argument.
534
+ # The `&` argument preserves the tricks if a Proc object is given by `&`
535
+ # argument.
346
536
  #
347
- # ```ruby
348
- # n(&lambda {}) #=> true
349
- # n(&proc {}) #=> false
350
- # n(&Proc.new {}) #=> false
351
- # ```
537
+ # n(&lambda {}) #=> true
538
+ # n(&proc {}) #=> false
539
+ # n(&Proc.new {}) #=> false
352
540
  #
353
- # A [Proc](Proc.downloaded.ruby_doc) object converted from a method has no
354
- # tricks.
541
+ # A Proc object converted from a method has no tricks.
355
542
  #
356
- # ```ruby
357
- # def m() end
358
- # method(:m).to_proc.lambda? #=> true
543
+ # def m() end
544
+ # method(:m).to_proc.lambda? #=> true
359
545
  #
360
- # n(&method(:m)) #=> true
361
- # n(&method(:m).to_proc) #=> true
362
- # ```
546
+ # n(&method(:m)) #=> true
547
+ # n(&method(:m).to_proc) #=> true
363
548
  #
364
- # `define_method` is treated the same as method definition. The defined
365
- # method has no tricks.
549
+ # `define_method` is treated the same as method definition. The defined method
550
+ # has no tricks.
366
551
  #
367
- # ```ruby
368
- # class C
369
- # define_method(:d) {}
370
- # end
371
- # C.new.d(1,2) #=> ArgumentError
372
- # C.new.method(:d).to_proc.lambda? #=> true
373
- # ```
552
+ # class C
553
+ # define_method(:d) {}
554
+ # end
555
+ # C.new.d(1,2) #=> ArgumentError
556
+ # C.new.method(:d).to_proc.lambda? #=> true
374
557
  #
375
558
  # `define_method` always defines a method without the tricks, even if a
376
- # non-lambda [Proc](Proc.downloaded.ruby_doc) object is given. This is the
377
- # only exception for which the tricks are not preserved.
378
- #
379
- # ```ruby
380
- # class C
381
- # define_method(:e, &proc {})
382
- # end
383
- # C.new.e(1,2) #=> ArgumentError
384
- # C.new.method(:e).to_proc.lambda? #=> true
385
- # ```
386
- #
387
- # This exception ensures that methods never have tricks and makes it easy
388
- # to have wrappers to define methods that behave as usual.
389
- #
390
- # ```ruby
391
- # class C
392
- # def self.def2(name, &body)
393
- # define_method(name, &body)
394
- # end
395
- #
396
- # def2(:f) {}
397
- # end
398
- # C.new.f(1,2) #=> ArgumentError
399
- # ```
559
+ # non-lambda Proc object is given. This is the only exception for which the
560
+ # tricks are not preserved.
561
+ #
562
+ # class C
563
+ # define_method(:e, &proc {})
564
+ # end
565
+ # C.new.e(1,2) #=> ArgumentError
566
+ # C.new.method(:e).to_proc.lambda? #=> true
567
+ #
568
+ # This exception ensures that methods never have tricks and makes it easy to
569
+ # have wrappers to define methods that behave as usual.
570
+ #
571
+ # class C
572
+ # def self.def2(name, &body)
573
+ # define_method(name, &body)
574
+ # end
575
+ #
576
+ # def2(:f) {}
577
+ # end
578
+ # C.new.f(1,2) #=> ArgumentError
400
579
  #
401
580
  # The wrapper *def2* defines a method which has no tricks.
581
+ #
402
582
  def lambda?: () -> bool
403
583
 
584
+ # <!--
585
+ # rdoc-file=proc.c
586
+ # - prc.parameters -> array
587
+ # -->
404
588
  # Returns the parameter information of this proc.
405
589
  #
406
- # ```ruby
407
- # prc = lambda{|x, y=42, *other|}
408
- # prc.parameters #=> [[:req, :x], [:opt, :y], [:rest, :other]]
409
- # ```
590
+ # prc = lambda{|x, y=42, *other|}
591
+ # prc.parameters #=> [[:req, :x], [:opt, :y], [:rest, :other]]
592
+ #
410
593
  def parameters: () -> ::Array[[ Symbol, Symbol ]]
411
594
 
412
- # Returns the Ruby source filename and line number containing this proc or
413
- # `nil` if this proc was not defined in Ruby (i.e. native).
595
+ # <!--
596
+ # rdoc-file=proc.c
597
+ # - prc.source_location -> [String, Integer]
598
+ # -->
599
+ # Returns the Ruby source filename and line number containing this proc or `nil`
600
+ # if this proc was not defined in Ruby (i.e. native).
601
+ #
414
602
  def source_location: () -> [ String, Integer ]
415
603
 
416
- # Part of the protocol for converting objects to `Proc` objects. Instances
417
- # of class `Proc` simply return themselves.
604
+ # <!--
605
+ # rdoc-file=proc.c
606
+ # - prc.to_proc -> proc
607
+ # -->
608
+ # Part of the protocol for converting objects to Proc objects. Instances of
609
+ # class Proc simply return themselves.
610
+ #
418
611
  def to_proc: () -> self
419
612
 
420
- # Returns the unique identifier for this proc, along with an indication of
421
- # where the proc was defined.
422
- #
613
+ # <!--
614
+ # rdoc-file=proc.c
615
+ # - prc.to_s -> string
616
+ # -->
617
+ # Returns the unique identifier for this proc, along with an indication of where
618
+ # the proc was defined.
423
619
  #
424
- #
425
- # Also aliased as: [inspect](Proc.downloaded.ruby_doc#method-i-inspect)
426
620
  def to_s: () -> String
427
621
 
428
- # Alias for: [to\_s](Proc.downloaded.ruby_doc#method-i-to_s)
622
+ # <!-- rdoc-file=proc.c -->
623
+ # Returns the unique identifier for this proc, along with an indication of where
624
+ # the proc was defined.
625
+ #
429
626
  def inspect: () -> String
430
627
  end